Plugins filter
This commit is contained in:
@@ -446,23 +446,22 @@ function initTabs()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------
|
// --------------------------------------------------------
|
||||||
// Data cleanup/purge functionality
|
// Filter method taht determines if an entry should be shown
|
||||||
function shouldBeShown(entry, pluginObj)
|
function shouldBeShown(entry, pluginObj)
|
||||||
{
|
{
|
||||||
if (pluginObj.hasOwnProperty('data_filters')) {
|
if (pluginObj.hasOwnProperty('data_filters')) {
|
||||||
|
|
||||||
let dataFilters = pluginObj.data_filters;
|
let dataFilters = pluginObj.data_filters;
|
||||||
|
|
||||||
// Loop through 'data_filters' array
|
// Loop through 'data_filters' array
|
||||||
for (let i = 0; i < dataFilters.length; i++) {
|
for (let i = 0; i < dataFilters.length; i++) {
|
||||||
|
|
||||||
// console.log(dataFilters[i])
|
|
||||||
compare_field_id = dataFilters[i].compare_field_id;
|
compare_field_id = dataFilters[i].compare_field_id;
|
||||||
compare_column = dataFilters[i].compare_column;
|
compare_column = dataFilters[i].compare_column;
|
||||||
compare_operator = dataFilters[i].compare_operator;
|
compare_operator = dataFilters[i].compare_operator;
|
||||||
compare_js_wrapper = dataFilters[i].compare_js_wrapper;
|
compare_js_wrapper = dataFilters[i].compare_js_wrapper;
|
||||||
compare_field_id_value = $(`#${compare_field_id}`).val();
|
compare_field_id_value = $(`#${compare_field_id}`).val();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(compare_field_id_value != undefined && compare_field_id_value != '--')
|
if(compare_field_id_value != undefined && compare_field_id_value != '--')
|
||||||
{
|
{
|
||||||
// valid value
|
// valid value
|
||||||
@@ -471,17 +470,10 @@ function shouldBeShown(entry, pluginObj)
|
|||||||
console.log(compare_operator)
|
console.log(compare_operator)
|
||||||
console.log(entry[compare_column])
|
console.log(entry[compare_column])
|
||||||
|
|
||||||
// console.log(entry[compare_column])
|
// resolve the left and right part of the comparison
|
||||||
// console.log(`"${compare_field_id_value}" ${compare_operator} "${entry[compare_column]}"`)
|
|
||||||
// console.log(`${compare_js_wrapper.replace('{value}', `"${compare_field_id_value}"`)} ${compare_operator} ${compare_js_wrapper.replace('{value}', `"${entry[compare_column]}"`)}`)
|
|
||||||
// console.log(eval(`${compare_js_wrapper.replace('{value}', `"${compare_field_id_value}"`)} ${compare_operator} ${compare_js_wrapper.replace('{value}', `"${entry[compare_column]}"`)}`))
|
|
||||||
let left = compare_js_wrapper.replace('{value}', `"${compare_field_id_value}"`)
|
let left = compare_js_wrapper.replace('{value}', `"${compare_field_id_value}"`)
|
||||||
let right = compare_js_wrapper.replace('{value}', `"${entry[compare_column]}"`)
|
let right = compare_js_wrapper.replace('{value}', `"${entry[compare_column]}"`)
|
||||||
|
|
||||||
console.log(`${eval(left)}` +
|
|
||||||
` ${compare_operator} ` +
|
|
||||||
`${eval(right)}`)
|
|
||||||
|
|
||||||
result = eval(
|
result = eval(
|
||||||
`${eval(left)}` +
|
`${eval(left)}` +
|
||||||
` ${compare_operator} ` +
|
` ${compare_operator} ` +
|
||||||
@@ -489,7 +481,6 @@ function shouldBeShown(entry, pluginObj)
|
|||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -193,6 +193,29 @@ Required `CMD` setting example with above query (you can set `"type": "label"` i
|
|||||||
|
|
||||||
Used to initialize internal settings. Check the `newdev_template` plugin for details.
|
Used to initialize internal settings. Check the `newdev_template` plugin for details.
|
||||||
|
|
||||||
|
## Filters
|
||||||
|
|
||||||
|
Plugin entries can be filtered based on values entered into filter fields. The `txtMacFilter` textbox/field contains the Mac address of the currently viewed device or simply a mac address that's available in the `mac` query string.
|
||||||
|
|
||||||
|
| Property | Required | Description |
|
||||||
|
|----------------------|----------------------|----------------------|
|
||||||
|
| `compare_column` | yes | Plugin column name that's value is used for comparison (**Left** side of the equation) |
|
||||||
|
| `compare_operator` | yes | JavaScript comparison operator |
|
||||||
|
| `compare_field_id` | yes | The `id` of a input text field containing a value is used for comparison (**Right** side of the equation)|
|
||||||
|
| `compare_js_wrapper` | yes | JavaScript code used to convert left and right side of the equation. `{value}` is replaced with input values. |
|
||||||
|
|
||||||
|
|
||||||
|
```json
|
||||||
|
"data_filters": [
|
||||||
|
{
|
||||||
|
"compare_column" : "Object_PrimaryID",
|
||||||
|
"compare_operator" : "==",
|
||||||
|
"compare_field_id": "txtMacFilter",
|
||||||
|
"compare_js_wrapper": "'{value}.toString()'"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
```
|
||||||
|
|
||||||
### Mapping the plugin results into a database table
|
### Mapping the plugin results into a database table
|
||||||
|
|
||||||
PiAlert will take the results of the plugin execution and insert these results into a database table, if a plugin contains the property `"mapped_to_table"` in the `config.json` root. The mapping of the columns is defined in the `database_column_definitions` array.
|
PiAlert will take the results of the plugin execution and insert these results into a database table, if a plugin contains the property `"mapped_to_table"` in the `config.json` root. The mapping of the columns is defined in the `database_column_definitions` array.
|
||||||
|
|||||||
@@ -3,6 +3,14 @@
|
|||||||
"unique_prefix": "DHCPLSS",
|
"unique_prefix": "DHCPLSS",
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"data_source": "python-script",
|
"data_source": "python-script",
|
||||||
|
"data_filters": [
|
||||||
|
{
|
||||||
|
"compare_column" : "Object_PrimaryID",
|
||||||
|
"compare_operator" : "==",
|
||||||
|
"compare_field_id": "txtMacFilter",
|
||||||
|
"compare_js_wrapper": "'{value}.toString()'"
|
||||||
|
}
|
||||||
|
],
|
||||||
"localized": ["display_name", "description", "icon"],
|
"localized": ["display_name", "description", "icon"],
|
||||||
"mapped_to_table": "DHCP_Leases",
|
"mapped_to_table": "DHCP_Leases",
|
||||||
"display_name" : [{
|
"display_name" : [{
|
||||||
|
|||||||
@@ -2,7 +2,15 @@
|
|||||||
"code_name": "snmp_discovery",
|
"code_name": "snmp_discovery",
|
||||||
"unique_prefix": "SNMPDSC",
|
"unique_prefix": "SNMPDSC",
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"data_source": "python-script",
|
"data_source": "pyton-script",
|
||||||
|
"data_filters": [
|
||||||
|
{
|
||||||
|
"compare_column" : "Object_PrimaryID",
|
||||||
|
"compare_operator" : "==",
|
||||||
|
"compare_field_id": "txtMacFilter",
|
||||||
|
"compare_js_wrapper": "'{value}.toString()'"
|
||||||
|
}
|
||||||
|
],
|
||||||
"localized": ["display_name", "description", "icon"],
|
"localized": ["display_name", "description", "icon"],
|
||||||
"mapped_to_table": "DHCP_Leases",
|
"mapped_to_table": "DHCP_Leases",
|
||||||
"display_name" : [{
|
"display_name" : [{
|
||||||
|
|||||||
@@ -3,6 +3,14 @@
|
|||||||
"unique_prefix": "UNFIMP",
|
"unique_prefix": "UNFIMP",
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"data_source": "python-script",
|
"data_source": "python-script",
|
||||||
|
"data_filters": [
|
||||||
|
{
|
||||||
|
"compare_column" : "Object_PrimaryID",
|
||||||
|
"compare_operator" : "==",
|
||||||
|
"compare_field_id": "txtMacFilter",
|
||||||
|
"compare_js_wrapper": "'{value}.toString()'"
|
||||||
|
}
|
||||||
|
],
|
||||||
"localized": ["display_name", "description", "icon"],
|
"localized": ["display_name", "description", "icon"],
|
||||||
"mapped_to_table": "DHCP_Leases",
|
"mapped_to_table": "DHCP_Leases",
|
||||||
"display_name" : [{
|
"display_name" : [{
|
||||||
|
|||||||
Reference in New Issue
Block a user