-
Notifications
You must be signed in to change notification settings - Fork 4
Examples
Nuno Aguiar edited this page Mar 14, 2018
·
3 revisions
nAttrMon YAML/JSON based Inputs, Output or Validations can be created in the same folders as the regular JS based Inputs, Outputs and Validations.
The following are three ways of implementing the same Input in YAML, JSON and Javascript:
input:
name : Test input
cron : "*/10 * * * * *"
waitForFinish: true
onlyOnEvent : true
execFrom : nInput_DB
execArgs :
key: MYAPP_DAT
sqls:
Database/Test 1 : >
SELECT user FROM dual
Database/Test 2 : >
SELECT level "My level"
FROM dual connect by level <= 5
{
input: {
name: "Test input",
cron: "*/10 * * * * *",
waitForFinish: true,
onlyOnEvent: true,
execFrom: "nInput_DB",
execArgs: {
key: "MYAPP_DAT",
sqls: {
"Database/Test 1": "SELECT user FROM dual",
"Database/Test 2": "SELECT level \"My level\" FROM dual connect by level <= 5"
}
}
}
}
nattrmon.addInput({
name: "Test input",
cron: "*/10 * * * * *",
waitForFinish: true,
onlyOnEvent: true
}, new nInput_DB({
key: "MYAPP_DAT",
sqls: {
"Database/Test 1": "SELECT user FROM dual",
"Database/Test 2": "SELECT level \"My level\" FROM dual connect by level <= 5"
}
}));
The following example builds a json string to provide, as Input, the current number of processes and files vs the current limitations.
input:
name : Processes and files limits
cron : "*/5 * * * *"
waitForFinish: true
onlyOnEvent : true
execFrom : nInput_Shell
execArgs :
name : Processes and files limits
attrTemplate: Server/Status processes and files limits
cmd : "echo \"{ \\\"maxFilesPerUser\\\": \"`ulimit -n`\", \\\"currentFilesPerUser\\\": \"`lsof -u myuser | wc -l`\", \\\"numberOfProcesses\\\": \"`ps h -u myuser | wc | awk '{print $1}'`\", \\\"maxNumberOfProcesses\\\": `bash -c 'ulimit -u'` }\""
parseJson : true
{
input: {
name: "Processes and files limits",
cron: "*/5 * * * *",
waitForFinish: true,
onlyOnEvent: true,
execFrom: "nInput_Shell",
execArgs: {
name: "Processes and files limits",
attrTemplate: "Server/Status processes and files limits",
cmd: "echo \"{ \\\"maxFilesPerUser\\\": \"`ulimit -n`\", \\\"currentFilesPerUser\\\": \"`lsof -u myuser | wc -l`\", \\\"numberOfProcesses\\\": \"`ps h -u myuser | wc | awk '{print $1}'`\", \\\"maxNumberOfProcesses\\\": `bash -c 'ulimit -u'` }\"",
parseJson: true
}
}
}
nattrmon.addInput({
name: "Processes and files limits",
cron: "*/5 * * * *",
waitForFinish: true,
onlyOnEvent: true
}, new nInput_Shell({
name: "Processes and files limits",
attrTemplate: "Server/Status processes and files limits",
cmd: "echo \"{ \\\"maxFilesPerUser\\\": \"`ulimit -n`\", \\\"currentFilesPerUser\\\": \"`lsof -u myuser | wc -l`\", \\\"numberOfProcesses\\\": \"`ps h -u myuser | wc | awk '{print $1}'`\", \\\"maxNumberOfProcesses\\\": `bash -c 'ulimit -u'` }\"",
parseJson: true
}));
input:
name : Test input unique name
timeInterval : 10000
waitForFinish: true
onlyOnEvent : true
exec : |
var attrName = "Category examples/My new example";
var res = {};
// Get the input info you need
// res[attrName] = a map or array of info collected to be added/updated on the attribute
return res;
{
input: {
name: "Test input unique name",
timeInterval: 10000,
waitForFinish: true,
onlyOnEvent: true,
exec: "var attrName = \"Category examples/My new example\"; var res = {}; /* Get the input info you need */ /* res[attrName] = a map or array of info collected to be added/updated on the attribute */ return res;"
}
}
nattrmon.addInput({
name: "Test input unique name",
timeInterval: 10000,
waitForFinish: true,
onlyOnEvent: true
}, new nInput(function(scope, args) {
var attrName = "Category examples/My new example";
var res = {};
// Get the input info you need
// res[attrName] = a map or array of info collected to be added/updated on the attribute
return res;
}));
validation:
name : Test validation unique name
timeInterval : 10000
waitForFinish: true
onlyOnEvent : true
exec : |
var attrName = "Category examples/My new example";
var res = [];
var attrs = nattrmon.getCurrentValues();
var lastAttrs = nattrmon.getLastValues();
var warns = nattrmon.getWarnings();
if (isUnDef(attrs[attrName])) return res;
// if (attrs[attrName] ... and test what you need. If it should alert:
// Alerts levels can be LEVEL_HIGH, LEVEL_MEDIUM and LEVEL_LOW
res.push(new nWarning(nWarning.LEVEL_HIGH, "A simple unique alert title", "An alert description"));
// else ... don't forget to close the warning if it's no longer occurring:
this.closeWarning("A simple unique alert title");
// You can also add informative warnings:
res.push(new nWarning(nWarning.LEVEL_INFO, "A simple unique alert title", "An alert description"));
return res;
{
"validation": {
"name": "Test validation unique name",
"timeInterval": 10000,
"waitForFinish": true,
"onlyOnEvent": true,
"exec": "var attrName = \"Category examples/My new example\"; var res = []; var attrs = nattrmon.getCurrentValues(); var lastAttrs = nattrmon.getLastValues(); var warns = nattrmon.getWarnings(); if (isUnDef(attrs[attrName])) return res; /* if (attrs[attrName] ... and test what you need. If it should alert: Alerts levels can be LEVEL_HIGH, LEVEL_MEDIUM and LEVEL_LOW */ res.push(new nWarning(nWarning.LEVEL_HIGH, \"A simple unique alert title\", \"An alert description\")); /* else ... don't forget to close the warning if it's no longer occurring:*/ this.closeWarning(\"A simple unique alert title\"); /* You can also add informative warnings:*/ res.push(new nWarning(nWarning.LEVEL_INFO, \"A simple unique alert title\", \"An alert description\")); return res;"
}
}
nattrmon.addValidation({
name: "Test validation unique name",
timeInterval: 10000,
waitForFinish: true,
onlyOnEvent: true
}, new nVaidation(function(warns, scope, args) {
var attrName = "Category examples/My new example";
var res = [];
var attrs = nattrmon.getCurrentValues();
var lastAttrs = nattrmon.getLastValues();
var warns = nattrmon.getWarnings();
if (isUnDef(attrs[attrName])) return res;
// if (attrs[attrName] ... and test what you need. If it should alert:
// Alerts levels can be LEVEL_HIGH, LEVEL_MEDIUM and LEVEL_LOW
res.push(new nWarning(nWarning.LEVEL_HIGH, "A simple unique alert title", "An alert description"));
// else ... don't forget to close the warning if it's no longer occurring:
this.closeWarning("A simple unique alert title");
// You can also add informative warnings:
res.push(new nWarning(nWarning.LEVEL_INFO, "A simple unique alert title", "An alert description"));
return res;
}));
output:
name : Test output unique name
timeInterval : 10000
waitForFinish: true
onlyOnEvent : true
exec : |
var attrs = nattrmon.getCurrentValues();
var lastAttrs = nattrmon.getLastValues();
var warns = nattrmon.getWarnings();
// Do something with attrs, lastAttrs and warns
{
"output": {
"name": "Test output unique name",
"timeInterval": 10000,
"waitForFinish": true,
"onlyOnEvent": true,
"exec": "var attrs = nattrmon.getCurrentValues(); var lastAttrs = nattrmon.getLastValues(); var warns = nattrmon.getWarnings();";
}
}
nattrmon.addOutput({
name: "Test output unique name",
timeInterval: 10000,
waitForFinish: true,
onlyOnEvent: true
}, new nInput(function(scope, args) {
var attrs = nattrmon.getCurrentValues();
var lastAttrs = nattrmon.getLastValues();
var warns = nattrmon.getWarnings();
// Do something with attrs, lastAttrs and warns
}));