Plugins 0.1 - List param working

This commit is contained in:
Jokob-sk
2023-02-11 16:11:27 +11:00
parent 33f0356ca7
commit 170e61e73f
7 changed files with 243 additions and 79 deletions

View File

@@ -276,7 +276,8 @@ function saveSettings()
{
if($setting[2] == 'text' or $setting[2] == 'password' or $setting[2] == 'readonly' or $setting[2] == 'selecttext')
{
$txt = $txt.$setting[1]."='".$setting[3]."'\n" ;
$val = encode_single_quotes($setting[3]);
$txt = $txt.$setting[1]."='".$val."'\n" ;
} elseif($setting[2] == 'integer' or $setting[2] == 'selectinteger')
{
$txt = $txt.$setting[1]."=".$setting[3]."\n" ;
@@ -290,12 +291,18 @@ function saveSettings()
$txt = $txt.$setting[1]."=".$val."\n" ;
}elseif($setting[2] == 'multiselect' or $setting[2] == 'subnets' or $setting[2] == 'list')
{
$temp = '[';
foreach($setting[3] as $val)
{
$temp = $temp."'". $val."',";
$temp = '[';
if (count($setting) > 3 && is_array( $setting[3]) == True){
foreach($setting[3] as $val)
{
$temp = $temp."'". encode_single_quotes($val)."',";
}
$temp = substr_replace($temp, "", -1); // remove last comma ','
}
$temp = substr_replace($temp, "", -1).']'; // close brackets and remove last comma ','
$temp = $temp.']'; // close brackets
$txt = $txt.$setting[1]."=".$temp."\n" ;
}
}
@@ -321,8 +328,6 @@ function saveSettings()
}
// -------------------------------------------------------------------------------------------
function getString ($codeName, $default) {
$result = lang($codeName);
@@ -337,6 +342,16 @@ function getString ($codeName, $default) {
// -------------------------------------------------------------------------------------------
function encode_single_quotes ($val) {
$result = str_replace ('\'','_single_quote_',$val);
return $result;
}
// -------------------------------------------------------------------------------------------
function getDateFromPeriod () {
$period = $_REQUEST['period'];
return '"'. date ('Y-m-d', strtotime ('+1 day -'. $period) ) .'"';

View File

@@ -20,9 +20,14 @@
"value" : "SELECT dev_MAC from DEVICES"
},
{
"name" : "sites",
"name" : "urls",
"type" : "setting",
"value" : "WEBMON_LIST"
"value" : "WEBMON_urls_to_check"
},
{
"name" : "internet_ip",
"type" : "setting",
"value" : "WEBMON_SQL_internet_ip"
}],
"database_column_aliases":{
"Plugins_Events":{
@@ -50,7 +55,8 @@
},
"settings":[
{
"type": "RUN",
"function": "RUN",
"type": "selecttext",
"default_value":"disabled",
"options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"],
"localized": ["name", "description"],
@@ -64,7 +70,23 @@
}]
},
{
"type": "FORCE_REPORT",
"function": "CMD",
"type": "text",
"default_value":"python3 /home/pi/pialert/front/plugins/website_monitor/script.py urls={urls}",
"options": [],
"localized": ["name", "description"],
"name" : [{
"language_code":"en_us",
"string" : "Command"
}],
"description": [{
"language_code":"en_us",
"string" : "Comamnd to run"
}]
},
{
"function": "FORCE_REPORT",
"type": "boolean",
"default_value": false,
"options": [],
"localized": ["name", "description"],
@@ -83,7 +105,8 @@
},
{
"type": "RUN_SCHD",
"function": "RUN_SCHD",
"type": "text",
"default_value":"0 2 * * *",
"options": [],
"localized": ["name", "description"],
@@ -97,7 +120,8 @@
}]
},
{
"type": "API_SQL",
"function": "API_SQL",
"type": "text",
"default_value":"SELECT * FROM plugin_website_monitor",
"options": [],
"localized": ["name", "description"],
@@ -111,7 +135,8 @@
}]
},
{
"type": "RUN_TIMEOUT",
"function": "RUN_TIMEOUT",
"type": "integer",
"default_value":5,
"options": [],
"localized": ["name", "description"],
@@ -125,7 +150,8 @@
}]
},
{
"type": "WATCH",
"function": "WATCH",
"type": "multiselect",
"default_value":["Watched_Value1"],
"options": ["Watched_Value1","Watched_Value2","Watched_Value3","Watched_Value4"],
"localized": ["name", "description"],
@@ -139,22 +165,9 @@
}]
},
{
"type": "CMD",
"default_value":"python3 script.py",
"options": [],
"localized": ["name", "description"],
"name" : [{
"language_code":"en_us",
"string" : "Command"
}],
"description": [{
"language_code":"en_us",
"string" : "Change the <a href=\"https://linux.die.net/man/1/dig\" target=\"_blank\">dig utility</a> arguments if you have issues resolving your Internet IP. Arguments are added at the end of the following command: <code>dig +short </code>."
}]
},
{
"type": "LIST",
"default_value":"",
"function": "urls_to_check",
"type": "list",
"default_value":[],
"options": [],
"localized": ["name", "description"],
"name" : [{
@@ -163,7 +176,22 @@
}],
"description": [{
"language_code":"en_us",
"string" : "Change the <a href=\"https://linux.die.net/man/1/dig\" target=\"_blank\">dig utility</a> arguments if you have issues resolving your Internet IP. Arguments are added at the end of the following command: <code>dig +short </code>."
"string" : "Services to watch. Enter full URL, e.g. <code>https://google.com</code>."
}]
},
{
"function": "SQL_internet_ip",
"type": "readonly",
"default_value":"SELECT dev_LastIP FROM Devices WHERE dev_MAC = 'Internet'",
"options": [],
"localized": ["name", "description"],
"name" : [{
"language_code":"en_us",
"string" : "Helper variable"
}],
"description": [{
"language_code":"en_us",
"string" : "Getting the IP address of the Router / Internet"
}]
}

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env python
# Based on the work of https://github.com/leiweibau/Pi.Alert
# /home/pi/pialert/front/plugins/website_monitoring/script.py urls=http://google.com,http://bing.com
# /home/pi/pialert/front/plugins/website_monitor/script.py urls=http://google.com,http://bing.com
from __future__ import unicode_literals
from time import sleep, time, strftime
import requests

View File

@@ -1,2 +0,0 @@
http://google.com|null|2023-02-05 15:23:04|200|0.407871|null|null|null
http://bing.com|null|2023-02-05 15:23:04|200|0.196052|null|null|null

View File

@@ -1,13 +0,0 @@
Pi.Alert [Prototype]:
---------------------------------------------------------
Current User: root
Monitor Web-Services
Timestamp: 2023-02-05 15:23:03
Start Services Monitoring
| Timestamp | URL | StatusCode | ResponseTime |
-----------------------------------------------
2023-02-05 15:23:04 | http://google.com | 200 | 0.407871
2023-02-05 15:23:04 | http://bing.com | 200 | 0.196052