Sensu custom parameter in event data - sensu

I would like to add custom key/value pairs to the event data in sensu. I added the keys to the event definition, but it's not there by the time it gets to the handlers.
So what i want to achieve is to have the data behind the "custom_values" key at the point the check data is passed to the handler. (see example)
{
"checks": {
"check-disk": {
"command": "/etc/sensu/plugins/check-disk.rb",
"interval": 60,
"handlers": [
"default"
],
"subscribers": [
"default"
],
"standalone": false
"custom_values": {
"custom1": "somevalue"
}
}
}
}
Mutators won't help, AFAIK they can only work with the check data, which is not containing the custom key when the mutator gets the check result.
Thanks

Not much to go on as to how you're trying to use it, but there are a couple items you'll want to be sure of.
First off, the checks json provided is malformed, prior to defining your custom_values, you need a comma after "standalone": false
As such:
"standalone": false,
"custom_values": {
"custom1": "somevalue"
}
Second, when you go to use this custom_value data in your handler, make sure you're addressing it as part of the check:
#event['check']['custom_values']['custom1']
and not just trying to use it directly off the event, i.e.
#event['custom_values']['custom1']

This should work. Can you be sure that this check is not defined in on the client as well?
Additionally, did you remember to restart the sensu server to pick up the new definition?

Related

How do I create a custom Semantic Token for VSCode?

I'm creating a color theme and I found out that the only way to target function parameters with italic is by using semantic highlight. The problem is that since semantic highlight overrides some settings, I lost the ability to target support.function.console - the "log" of console.log, for instance.
.log is a member.defaultLibrary, but if I target that by semantic, some other things would also be styled with the same color. That wouldn't be bad if member.defaultLibrary wasn't so inconsistent, some things you would expect to be styled, is not, which leads to inconsistency, which is certainly not desirable.
querySelector() is styled by member.defaultLibrary but not querySelectorAll(), for instance. I also tried to not use anything that can be overridden by semantics but then, it creates too many exceptions and some functions and methods would be let without any style, which is much worse.
I've tried Semantic Token Classification and tried to add a custom semantic token to the package.json file of the extension but I don't know how to "wire" that up:
{
"contributes": {
"semanticTokenTypes": [
{
"id": "consoleSupport",
"description": "console support"
}
],
"semanticTokenScopes": [
{
"scopes": {
"consoleSupport": ["support.function.console"]
}
}
]
}
}
When using development host, it does recognize the "new" consoleSupport when I try to add to "semanticTokenColors", it suggests the auto-complete, so I'm probably half-way there but I don't know how to actually create the new token and how to make it work.

Am I understanding this VS Code API behavior correctly? Non-default *object* settings (when provided) are always merged?

I'm working on a VS Code Extension, and I think maybe I'm missing something in the docs, or else the behavior I'm seeing just isn't specified there, and my assumptions are wrong...?
I've defined some default settings for my extension, like so...
package.json
"contributes": {
"configuration": {
"title": "ToggleSettingsChanges",
"properties": {
"toggleSettingsChanges.settingsToToggle": {
"scope": "resource",
"type": "object",
"default": {
"window.zoomLevel": 2,
"editor.fontSize": 22,
"terminal.integrated.fontSize": 16,
"scm.diffDecorations": "none",
"workbench.statusBar.visible": false,
"editor.cursorBlinking": "solid",
"workbench.activityBar.visible": false
},
"description": "[ snip ]"
}
}
}
},
extension.js
// In the "main" method that runs when a command is activated:
const config = vscode.workspace.getConfiguration("toggleSettingsChanges");
const settingsToToggle = config.get("settingsToToggle");
const inspectedSettingsToToggle = config.inspect("settingsToToggle");
console.log("settingsToToggle:", JSON.stringify(settingsToToggle), "\n\n")
console.log("inspected settingsToToggle:", JSON.stringify(inspectedSettingsToToggle), "\n\n")
return;
In the Extension Host instance, I can tweak and adjust the settings, to include this:
User or Workspace Settings JSON
// ...
"toggleSettingsChanges.settingsToToggle": {
"editor.fontSize": 11,
"pumpkins_are_great": true
},
In the console output, I'm seeing the following:
settingsToToggle: {"window.zoomLevel":2,"editor.fontSize":11,"terminal.integrated.fontSize":16,"scm.diffDecorations":"none","workbench.statusBar.visible":false,"editor.cursorBlinking":"solid","workbench.activityBar.visible":false,"pumpkins_are_great":true}
inspected settingsToToggle: {"key":"toggleSettingsChanges.settingsToToggle","defaultValue":{"window.zoomLevel":2,"editor.fontSize":22,"terminal.integrated.fontSize":16,"scm.diffDecorations":"none","workbench.statusBar.visible":false,"editor.cursorBlinking":"solid","workbench.activityBar.visible":false},"globalValue":{"editor.fontSize":11,"pumpkins_are_great":true}}
For the settingsToToggle line, I expected to see only the following settings:
{"editor.fontSize":11,"pumpkins_are_great":true}
It seems that if you provide an object default, any configuration provided is merged with that object, instead of replacing it entirely.
Is that the case? Have I missed this in the documentation?
It seems to me that a value (even an object) would be overwritten, and not simply merged.
The documentation may have been updated since this question was posted. The way it's written now, seems pretty clear to me. I'm writing because I feel I have found a discrepancy in the API, which may help out the OP.
Reference
Note: Only object value types are merged and all other value types are overridden.
-- VS Code API - WorkspaceConfiguration
Additional information
I want my default values to be merged with the user settings, as is described above. I was confused by seeing my defaults overriden. This question helped me understand what is happening. I'll share my approach since OP may be interested. My observations:
Default values provided in package.json are merged with user settings, as described in the documentation (link above).
Default values passed programmatically with WorkspaceConfiguration.get(section, defaultValue) do not exhibit the merging behavior. It's not clear if this is intentional or not. Update: this behavior is working as intended, reference #105598.

vscode - Is there a way to manually trigger events?

I am running a callback on the workspace.onWillSaveTextDocument handler. It provides vscode.TextDocument and this is necessary for the work I want to do on this event.
In certain cases, I want to treat other files (that aren't currently open) as if they had just been saved, as well.
It would suffice to be able to create a new instance of vscode.TextDocument, but I was unable to figure that out.
Is there a way to do something like:
workspace.pretendThisWasSavedJustNow('/path/to/other/file.ts');
I work on VSCode and while I don't know your exact use case, I believe you are looking for workspace.openTextDocument.
To use the same function for workspace.onWillSaveTextDocument and on some other event that your extension triggers, try something like:
// Actual save
workspace.onWillSaveTextDocument(e => onDocumentSave(e.document))
// Emulated save
setInterval(() => {
workspace.openTextDocument('path/to/other/file.ts')
.then(document => onDocumentSave(document))
}, 5000)
// Common save handling implementation
function onDocumentSave(document: TextDocument) { ... }

I want to route a key to a different view?

I'm reading the official documentation. However it only shows me how to route the model to a different view and I want to route a key? Experts any suggestions?
To pass data between Views you could either use a Model with is accessible to both - for example one that has been created in the Component.
Or you could add a query parameter to your routing to enable the user to bookmark the state. For that, modify the route-pattern to look like this:
{
"pattern": "employees/{employeeId}/resume:?query:",
"name": "employeeResume",
"target": "employeeResume"
}
When you do a navigation you can then add any key-value pairs to your URL to transfer data between views. The following call will make the URL-hash look like this: #/employees/3/resume?tab=Projects
oRouter.navTo("employeeResume", {
employeeId : 3,
query: {
tab : "Projects"
}
});
Examples taken from the Developer Guide. Also see the API Reference for Route.

How do I add properties to a js-data object that I don't want persisted?

I'm using js-data (and js-data-angular) in conjunction with sockets via sails.js. When a new item is created/updated via sockets I want to call attention to it in my ui.
I'd like to add an "updated" property to the object, but don't want to inadvertently persist it to the DB.
Is there a way to hang non-persisting properties on a js-data object?
Yes.
You can set this globally on the data store or per-resource by using the omit configuration setting. For instance, when instancing your data store, you can instruct JSData to ignore all properties that begin with an underscore:
var store = new JSData.DS({ omit: [ /^_/ ] });
The documentation for the meta property of the options passed to store.defineResource says:
Put anything you want here. It will never be used by the API.