Plugins filter

This commit is contained in:
Jokob-sk
2023-07-20 19:11:43 +10:00
parent 1dbdf425d6
commit 98745805d3
5 changed files with 56 additions and 18 deletions

View File

@@ -446,22 +446,21 @@ function initTabs()
}
// --------------------------------------------------------
// Data cleanup/purge functionality
// Filter method taht determines if an entry should be shown
function shouldBeShown(entry, pluginObj)
{
if (pluginObj.hasOwnProperty('data_filters')) {
let dataFilters = pluginObj.data_filters;
// Loop through 'data_filters' array
for (let i = 0; i < dataFilters.length; i++) {
// console.log(dataFilters[i])
compare_field_id = dataFilters[i].compare_field_id;
compare_column = dataFilters[i].compare_column;
compare_operator = dataFilters[i].compare_operator;
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 != '--')
{
@@ -470,26 +469,18 @@ function shouldBeShown(entry, pluginObj)
console.log(compare_column)
console.log(compare_operator)
console.log(entry[compare_column])
// console.log(entry[compare_column])
// 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]}"`)}`))
// resolve the left and right part of the comparison
let left = compare_js_wrapper.replace('{value}', `"${compare_field_id_value}"`)
let right = compare_js_wrapper.replace('{value}', `"${entry[compare_column]}"`)
console.log(`${eval(left)}` +
` ${compare_operator} ` +
`${eval(right)}`)
result = eval(
`${eval(left)}` +
` ${compare_operator} ` +
`${eval(right)}`
);
return result;
return result;
}
}
}

View File

@@ -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.
## 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
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.

View File

@@ -3,6 +3,14 @@
"unique_prefix": "DHCPLSS",
"enabled": true,
"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"],
"mapped_to_table": "DHCP_Leases",
"display_name" : [{

View File

@@ -2,7 +2,15 @@
"code_name": "snmp_discovery",
"unique_prefix": "SNMPDSC",
"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"],
"mapped_to_table": "DHCP_Leases",
"display_name" : [{

View File

@@ -3,6 +3,14 @@
"unique_prefix": "UNFIMP",
"enabled": true,
"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"],
"mapped_to_table": "DHCP_Leases",
"display_name" : [{