mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
Plugins 0.3 - UI custom form controls
This commit is contained in:
@@ -3929,7 +3929,7 @@ def process_plugin_events(plugin):
|
|||||||
if plugObj.status == 'new':
|
if plugObj.status == 'new':
|
||||||
createdTime = plugObj.changed
|
createdTime = plugObj.changed
|
||||||
|
|
||||||
sql.execute ("INSERT INTO Plugins_Events (Plugin, Object_PrimaryID, Object_SecondaryID, DateTimeCreated, DateTimeChanged, Watched_Value1, Watched_Value2, Watched_Value3, Watched_Value4, Status, Extra, UserData) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", (plugObj.pluginPref, plugObj.primaryId , plugObj.secondaryId , createdTime, plugObj.changed , plugObj.watched1 , plugObj.watched2 , plugObj.watched3 , plugObj.watched4 , plugObj.status , plugObj.extra, plugObj.userData ))
|
sql.execute ("INSERT INTO Plugins_Events (Index, Plugin, Object_PrimaryID, Object_SecondaryID, DateTimeCreated, DateTimeChanged, Watched_Value1, Watched_Value2, Watched_Value3, Watched_Value4, Status, Extra, UserData) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", (plugObj.index, plugObj.pluginPref, plugObj.primaryId , plugObj.secondaryId , createdTime, plugObj.changed , plugObj.watched1 , plugObj.watched2 , plugObj.watched3 , plugObj.watched4 , plugObj.status , plugObj.extra, plugObj.userData ))
|
||||||
|
|
||||||
commitDB()
|
commitDB()
|
||||||
|
|
||||||
@@ -3976,11 +3976,18 @@ class plugin_object_class:
|
|||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# Combine plugin objects, keep user-defined values, created time
|
# Combine plugin objects, keep user-defined values, created time, changed time if nothing changed and the index
|
||||||
def combine_plugin_objects(old, new):
|
def combine_plugin_objects(old, new):
|
||||||
|
|
||||||
new.userData = old.userData
|
new.userData = old.userData
|
||||||
|
new.index = old.index
|
||||||
new.created = old.created
|
new.created = old.created
|
||||||
|
|
||||||
|
# Keep changed time if nothing changed
|
||||||
|
if new.status in ['watched-not-changed']:
|
||||||
|
new.changed = old.changed
|
||||||
|
|
||||||
|
# return the new object, with some of the old values
|
||||||
return new
|
return new
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -36,6 +36,47 @@
|
|||||||
|
|
||||||
<script defer>
|
<script defer>
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Get form control according to the column definition from config.json > database_column_definitions
|
||||||
|
function getFormControl(index, dbColumnDef, value) {
|
||||||
|
|
||||||
|
result = ''
|
||||||
|
|
||||||
|
switch(dbColumnDef.type)
|
||||||
|
{
|
||||||
|
case 'label':
|
||||||
|
result = `<span>${value}<span>`;
|
||||||
|
break;
|
||||||
|
case 'text':
|
||||||
|
result = `<span><input type="text" value="${value}" id="${dbColumnDef.column}_${index}" name="${dbColumnDef.column}"><span>`;
|
||||||
|
break;
|
||||||
|
case 'url':
|
||||||
|
result = `<span><a href="${value}" target="_blank">${value}</a><span>`;
|
||||||
|
break;
|
||||||
|
case 'threshold':
|
||||||
|
$.each(dbColumnDef.options, function(index, obj) {
|
||||||
|
if(Number(value) < obj.maximum && result == '')
|
||||||
|
{
|
||||||
|
result = `<div style="background-color:${obj.hexColor}">${value}</div>`
|
||||||
|
// return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case 'replace':
|
||||||
|
$.each(dbColumnDef.options, function(index, obj) {
|
||||||
|
if(value == obj.equals)
|
||||||
|
{
|
||||||
|
result = `<span>${obj.replacement}</span>`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
result = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Get translated string
|
// Get translated string
|
||||||
function localize (obj, key) {
|
function localize (obj, key) {
|
||||||
@@ -51,7 +92,7 @@ function localize (obj, key) {
|
|||||||
{
|
{
|
||||||
code = obj[key][i]["language_code"]
|
code = obj[key][i]["language_code"]
|
||||||
|
|
||||||
console.log(code)
|
// console.log(code)
|
||||||
|
|
||||||
if( code == 'en_us')
|
if( code == 'en_us')
|
||||||
{
|
{
|
||||||
@@ -126,7 +167,7 @@ function generateTabs()
|
|||||||
|
|
||||||
// Generate the header
|
// Generate the header
|
||||||
$.each(obj["database_column_definitions"], function(index, colDef){
|
$.each(obj["database_column_definitions"], function(index, colDef){
|
||||||
if(colDef.show == true)
|
if(colDef.show == true) // select only the ones to show
|
||||||
{
|
{
|
||||||
colDefinitions.push(colDef)
|
colDefinitions.push(colDef)
|
||||||
headersHtml += `<th class="col-sm-2" >${localize(colDef, "name" )}</th>`
|
headersHtml += `<th class="col-sm-2" >${localize(colDef, "name" )}</th>`
|
||||||
@@ -161,7 +202,8 @@ function generateTabs()
|
|||||||
|
|
||||||
for(j=0;j<colDefinitions.length;j++)
|
for(j=0;j<colDefinitions.length;j++)
|
||||||
{
|
{
|
||||||
clm += '<td>'+ pluginObjects[i][colDefinitions[j].column] +'</td>'
|
|
||||||
|
clm += '<td>'+ getFormControl(i, colDefinitions[j], pluginObjects[i][colDefinitions[j].column]) +'</td>'
|
||||||
}
|
}
|
||||||
obRows += '<tr>' + clm + '</tr>'
|
obRows += '<tr>' + clm + '</tr>'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -166,18 +166,68 @@ Example:
|
|||||||
##### database_column_definitions
|
##### database_column_definitions
|
||||||
|
|
||||||
- Only columns with `"show": true` and also with at least an english translation will be shown in the UI.
|
- Only columns with `"show": true` and also with at least an english translation will be shown in the UI.
|
||||||
|
- The `options` property is used in conjunction with these types:
|
||||||
|
- `threshold` - The `options` array contains objects from lowest `maximum` to highest with corresponding `hexColor` used for the value background color if it's les sthan the specified `maximum`, but more than the previous one in the `options` array
|
||||||
|
- `replace` - The `options` array contains objects with an `equals` property, that is compared to the "value" and if the values are the same, the string in `replacement` is displayed in the UI instead of the actual "value"
|
||||||
|
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"column": "Index",
|
"column": "Watched_Value1",
|
||||||
"show": false,
|
"show": true,
|
||||||
"type": "label",
|
"type": "threshold",
|
||||||
"default_value":"",
|
"default_value":"",
|
||||||
"options": [],
|
"options": [
|
||||||
|
{
|
||||||
|
"maximum": 199,
|
||||||
|
"hexColor": "#792D86"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"maximum": 299,
|
||||||
|
"hexColor": "#5B862D"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"maximum": 399,
|
||||||
|
"hexColor": "#7D862D"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"maximum": 499,
|
||||||
|
"hexColor": "#BF6440"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"maximum": 599,
|
||||||
|
"hexColor": "#D33115"
|
||||||
|
}
|
||||||
|
],
|
||||||
"localized": ["name"],
|
"localized": ["name"],
|
||||||
"name":[{
|
"name":[{
|
||||||
"language_code":"en_us",
|
"language_code":"en_us",
|
||||||
"string" : "N/A"
|
"string" : "Status code"
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"column": "Status",
|
||||||
|
"show": true,
|
||||||
|
"type": "replace",
|
||||||
|
"default_value":"",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"equals": "watched-not-changed",
|
||||||
|
"replacement": "<i class='fa-solid fa-square-check'></i>"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"equals": "watched-changed",
|
||||||
|
"replacement": "<i class='fa-solid fa-triangle-exclamation'></i>"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"equals": "new",
|
||||||
|
"replacement": "<i class='fa-solid fa-circle-plus'></i>"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"localized": ["name"],
|
||||||
|
"name":[{
|
||||||
|
"language_code":"en_us",
|
||||||
|
"string" : "Status"
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -353,7 +403,7 @@ Example:
|
|||||||
{
|
{
|
||||||
"column": "Status",
|
"column": "Status",
|
||||||
"show": true,
|
"show": true,
|
||||||
"type": "label",
|
"type": "equals",
|
||||||
"default_value":"",
|
"default_value":"",
|
||||||
"options": [],
|
"options": [],
|
||||||
"localized": ["name"],
|
"localized": ["name"],
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
A simple sample plugin allowing for monitoring web services or urls.
|
A simple sample plugin allowing for monitoring web services or urls. The status code corresponds to the commonly used [HTTP response status codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status).
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
@@ -9,4 +9,4 @@ A simple sample plugin allowing for monitoring web services or urls.
|
|||||||
### Notes
|
### Notes
|
||||||
|
|
||||||
- Setting `(WEBMON_)SQL_internet_ip` is not used and specified for demonstration purposes only.
|
- Setting `(WEBMON_)SQL_internet_ip` is not used and specified for demonstration purposes only.
|
||||||
- Parameters `macs` and `internet_ip` are not used and specified for demonstration purposes only.
|
- Parameters `macs` and `internet_ip` in the `config.json` file are not used and specified for demonstration purposes only.
|
||||||
@@ -58,7 +58,7 @@
|
|||||||
{
|
{
|
||||||
"column": "Object_PrimaryID",
|
"column": "Object_PrimaryID",
|
||||||
"show": true,
|
"show": true,
|
||||||
"type": "text",
|
"type": "url",
|
||||||
"default_value":"",
|
"default_value":"",
|
||||||
"options": [],
|
"options": [],
|
||||||
"localized": ["name"],
|
"localized": ["name"],
|
||||||
@@ -82,7 +82,7 @@
|
|||||||
{
|
{
|
||||||
"column": "DateTimeCreated",
|
"column": "DateTimeCreated",
|
||||||
"show": true,
|
"show": true,
|
||||||
"type": "text",
|
"type": "label",
|
||||||
"default_value":"",
|
"default_value":"",
|
||||||
"options": [],
|
"options": [],
|
||||||
"localized": ["name"],
|
"localized": ["name"],
|
||||||
@@ -94,7 +94,7 @@
|
|||||||
{
|
{
|
||||||
"column": "DateTimeChanged",
|
"column": "DateTimeChanged",
|
||||||
"show": true,
|
"show": true,
|
||||||
"type": "text",
|
"type": "label",
|
||||||
"default_value":"",
|
"default_value":"",
|
||||||
"options": [],
|
"options": [],
|
||||||
"localized": ["name"],
|
"localized": ["name"],
|
||||||
@@ -106,9 +106,30 @@
|
|||||||
{
|
{
|
||||||
"column": "Watched_Value1",
|
"column": "Watched_Value1",
|
||||||
"show": true,
|
"show": true,
|
||||||
"type": "text",
|
"type": "threshold",
|
||||||
"default_value":"",
|
"default_value":"",
|
||||||
"options": [],
|
"options": [
|
||||||
|
{
|
||||||
|
"maximum": 199,
|
||||||
|
"hexColor": "#792D86"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"maximum": 299,
|
||||||
|
"hexColor": "#5B862D"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"maximum": 399,
|
||||||
|
"hexColor": "#7D862D"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"maximum": 499,
|
||||||
|
"hexColor": "#BF6440"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"maximum": 599,
|
||||||
|
"hexColor": "#D33115"
|
||||||
|
}
|
||||||
|
],
|
||||||
"localized": ["name"],
|
"localized": ["name"],
|
||||||
"name":[{
|
"name":[{
|
||||||
"language_code":"en_us",
|
"language_code":"en_us",
|
||||||
@@ -118,7 +139,7 @@
|
|||||||
{
|
{
|
||||||
"column": "Watched_Value2",
|
"column": "Watched_Value2",
|
||||||
"show": true,
|
"show": true,
|
||||||
"type": "text",
|
"type": "label",
|
||||||
"default_value":"",
|
"default_value":"",
|
||||||
"options": [],
|
"options": [],
|
||||||
"localized": ["name"],
|
"localized": ["name"],
|
||||||
@@ -166,9 +187,22 @@
|
|||||||
{
|
{
|
||||||
"column": "Status",
|
"column": "Status",
|
||||||
"show": true,
|
"show": true,
|
||||||
"type": "label",
|
"type": "replace",
|
||||||
"default_value":"",
|
"default_value":"",
|
||||||
"options": [],
|
"options": [
|
||||||
|
{
|
||||||
|
"equals": "watched-not-changed",
|
||||||
|
"replacement": "<i class='fa-solid fa-square-check'></i>"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"equals": "watched-changed",
|
||||||
|
"replacement": "<i class='fa-solid fa-triangle-exclamation'></i>"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"equals": "new",
|
||||||
|
"replacement": "<i class='fa-solid fa-circle-plus'></i>"
|
||||||
|
}
|
||||||
|
],
|
||||||
"localized": ["name"],
|
"localized": ["name"],
|
||||||
"name":[{
|
"name":[{
|
||||||
"language_code":"en_us",
|
"language_code":"en_us",
|
||||||
|
|||||||
Reference in New Issue
Block a user