mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
enable testing of notifications
This commit is contained in:
@@ -335,7 +335,7 @@ def importConfig ():
|
||||
PUSHSAFER_TOKEN = ccd('PUSHSAFER_TOKEN', 'ApiKey' , c_d, 'PUSHSAFER token', 'text', '', 'PUSHSAFER')
|
||||
|
||||
# MQTT
|
||||
REPORT_MQTT = ccd('REPORT_MQTT', False , c_d, 'Enable MQTT', 'boolean', '', 'MQTT', ['test'])
|
||||
REPORT_MQTT = ccd('REPORT_MQTT', False , c_d, 'Enable MQTT', 'boolean', '', 'MQTT')
|
||||
MQTT_BROKER = ccd('MQTT_BROKER', '' , c_d, 'MQTT broker', 'text', '', 'MQTT')
|
||||
MQTT_PORT = ccd('MQTT_PORT', 1883 , c_d, 'MQTT broker port', 'integer', '', 'MQTT')
|
||||
MQTT_USER = ccd('MQTT_USER', '' , c_d, 'MQTT user', 'text', '', 'MQTT')
|
||||
@@ -2423,7 +2423,7 @@ def send_webhook (_json, _html):
|
||||
if WEBHOOK_PAYLOAD == 'text':
|
||||
payloadData = to_text(_json)
|
||||
|
||||
#Define slack-compatible payload
|
||||
# Define slack-compatible payload
|
||||
_json_payload = { "text": payloadData } if WEBHOOK_PAYLOAD == 'text' else {
|
||||
"username": "Pi.Alert",
|
||||
"text": "There are new notifications",
|
||||
@@ -2767,7 +2767,7 @@ def upgradeDB ():
|
||||
('Back_Settings_Imported', round(time.time() * 1000)),
|
||||
('Back_App_State', 'Initializing'),
|
||||
('Back_New_Version_Available', False),
|
||||
('Front_Event', 'none')
|
||||
('Front_Event', 'finished')
|
||||
]
|
||||
|
||||
sql.executemany ("""INSERT INTO Parameters ("par_ID", "par_Value") VALUES (?, ?)""", params)
|
||||
@@ -2905,6 +2905,15 @@ def checkIPV4(ip):
|
||||
else:
|
||||
return False
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
def get_file_content(path):
|
||||
|
||||
f = open(path, 'r')
|
||||
content = f.read()
|
||||
f.close()
|
||||
|
||||
return content
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
def updateSubnets():
|
||||
@@ -3023,7 +3032,7 @@ def check_and_run_event():
|
||||
rows = sql.fetchall()
|
||||
|
||||
event, param = ['','']
|
||||
if len(rows) > 0 and rows[0]['par_Value'] != 'none':
|
||||
if len(rows) > 0 and rows[0]['par_Value'] != 'finished':
|
||||
event = rows[0]['par_Value'].split('|')[0]
|
||||
param = rows[0]['par_Value'].split('|')[1]
|
||||
else:
|
||||
@@ -3033,30 +3042,37 @@ def check_and_run_event():
|
||||
handle_test(param)
|
||||
|
||||
# clear event execution flag
|
||||
sql.execute ("UPDATE Parameters SET par_Value='none' WHERE par_ID='Front_Event'")
|
||||
sql.execute ("UPDATE Parameters SET par_Value='finished' WHERE par_ID='Front_Event'")
|
||||
|
||||
# commit to DB
|
||||
commitDB ()
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
def handle_test(testType):
|
||||
|
||||
file_print('[', timeNow(), '] START Test: ', testType)
|
||||
|
||||
# Open text sample
|
||||
sample_txt = get_file_content(pialertPath + '/back/report_sample_1.txt')
|
||||
|
||||
# Open html sample
|
||||
sample_html = get_file_content(pialertPath + '/back/report_sample_2.html')
|
||||
|
||||
# Open json sample and get only the payload part
|
||||
sample_json_payload = json.loads(get_file_content(pialertPath + '/back/webhook_json_sample.json'))[0]["body"]["attachments"][0]["text"]
|
||||
|
||||
if testType == 'REPORT_MAIL':
|
||||
test_email()
|
||||
send_email(sample_txt, sample_html)
|
||||
if testType == 'REPORT_WEBHOOK':
|
||||
send_webhook (sample_json_payload, sample_txt)
|
||||
if testType == 'REPORT_APPRISE':
|
||||
send_apprise (sample_html)
|
||||
if testType == 'REPORT_NTFY':
|
||||
send_ntfy (sample_txt)
|
||||
if testType == 'REPORT_PUSHSAFER':
|
||||
send_pushsafer (sample_txt)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
def test_email():
|
||||
|
||||
# Open text Template
|
||||
template_file = open(pialertPath + '/back/report_sample_1.txt', 'r')
|
||||
mail_text_txt = template_file.read()
|
||||
template_file.close()
|
||||
|
||||
# Open html Template
|
||||
template_file = open(pialertPath + '/back/report_sample_2.html', 'r')
|
||||
mail_text_html = template_file.read()
|
||||
template_file.close()
|
||||
|
||||
send_email(mail_text_txt, mail_text_html)
|
||||
file_print('[', timeNow(), '] END Test: ', testType)
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
@@ -7,9 +7,9 @@ services:
|
||||
network_mode: "host"
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- ${APP_DATA_LOCATION}/pialert/config2:/home/pi/pialert/config
|
||||
- ${APP_DATA_LOCATION}/pialert/config:/home/pi/pialert/config
|
||||
# - ${APP_DATA_LOCATION}/pialert/db/pialert.db:/home/pi/pialert/db/pialert.db
|
||||
- ${APP_DATA_LOCATION}/pialert/db2:/home/pi/pialert/db
|
||||
- ${APP_DATA_LOCATION}/pialert/db:/home/pi/pialert/db
|
||||
# (optional) map an empty file with the name 'setting_darkmode' if you want to force the dark mode on container rebuilt
|
||||
- ${APP_DATA_LOCATION}/pialert/db/setting_darkmode:/home/pi/pialert/db/setting_darkmode
|
||||
# (optional) useful for debugging if you have issues setting up the container
|
||||
|
||||
@@ -430,6 +430,17 @@ $lang['en_us'] = array(
|
||||
'HelpFAQ_Cat_Network_600_text' => 'This page should offer you the possibility to map the assignment of your network devices. For this purpose, you can create one or more switches, WLANs, routers, etc., provide them with a port number if necessary and assign already detected
|
||||
devices to them. This assignment is done in the detailed view of the device to be assigned. So it is possible for you to quickly determine to which port a host is connected and if it is online.',
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Front end events
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
'test_event_tooltip' => 'Save your changes at first before you test your settings.',
|
||||
'test_event_icon' => 'fa-vial-circle-check',
|
||||
'general_event_title' => 'Executing an ad-hoc event',
|
||||
'general_event_description' => 'The event you\'ve triggered might take a while until background processes finish. The execution ended once you see <code>finished</code> below. Check the <a onclick=\'setCache(\"activeMaintenanceTab\", \"tab_Logging_id\")\' href=\"/maintenance.php#tab_Logging\">error log</a> if you didn\'t get the expected result. <br/> <br/> Status: ',
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Settings
|
||||
//////////////////////////////////////////////////////////////////
|
||||
@@ -441,6 +452,7 @@ $lang['en_us'] = array(
|
||||
'settings_imported' => 'Last time settings were imported from the pialert.conf file:',
|
||||
'settings_expand_all' => 'Expand all',
|
||||
|
||||
|
||||
//General
|
||||
'ENABLE_ARPSCAN_name' => 'Enable ARP scan',
|
||||
'ENABLE_ARPSCAN_description' => 'Arp-scan is a command-line tool that uses the ARP protocol to discover and fingerprint IP hosts on the local network. An alternative to ARP scan is to enable the <a onclick="toggleAllSettings()" href="#PIHOLE_ACTIVE"><code>PIHOLE_ACTIVE</code>PiHole integration settings</a>.',
|
||||
|
||||
@@ -82,7 +82,7 @@ CommitDB();
|
||||
<h4 class="panel-title">'.$group.'</h4>
|
||||
</div>
|
||||
</a>
|
||||
<div id="'.$group.'" class="panel-collapse collapse '.$isIn.'">
|
||||
<div id="'.$group.'" data-myid="collapsible" class="panel-collapse collapse '.$isIn.'">
|
||||
<div class="panel-body">';
|
||||
$isIn = ' '; // open the first panel only by default on page load
|
||||
|
||||
@@ -234,20 +234,22 @@ CommitDB();
|
||||
|
||||
// render any buttons or additional actions if specified
|
||||
$eventsHtml = "";
|
||||
|
||||
// displayMessage($set['Events'], FALSE, TRUE, TRUE, TRUE);
|
||||
|
||||
// if available get all the events associated with this setting
|
||||
$eventsList = createArray($set['Events']);
|
||||
|
||||
$iconMap = [
|
||||
"test" => ["To test this configuration you have to save it at first.","fa-vial-circle-check"]
|
||||
];
|
||||
// icon map for the events
|
||||
// $iconMap = [
|
||||
// "test" => [lang("settings_event_tooltip"),""]
|
||||
// ];
|
||||
|
||||
if(count($eventsList) > 0)
|
||||
{
|
||||
foreach ($eventsList as $event) {
|
||||
$eventsHtml = $eventsHtml.'<span class="input-group-addon">
|
||||
<i title="'.$iconMap[$event][0].'" class="fa '.$iconMap[$event][1].' pointer" data-myparam="'.$set['Code_Name'].'" data-myevent="'.$event.'"></i>
|
||||
<i title="'.lang($event."_event_tooltip").'" class="fa '.lang($event."_event_icon").' pointer"
|
||||
data-myparam="'.$set['Code_Name'].'"
|
||||
data-myevent="'.$event.'">
|
||||
</i>
|
||||
</span>';
|
||||
}
|
||||
}
|
||||
@@ -385,7 +387,7 @@ CommitDB();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
function getParam(targetId, key, skipCache = false, callback) {
|
||||
function getParam(targetId, key, skipCache = false) {
|
||||
|
||||
skipCacheQuery = "";
|
||||
|
||||
@@ -395,7 +397,7 @@ CommitDB();
|
||||
}
|
||||
|
||||
// get parameter value
|
||||
$.get('php/server/parameters.php?action=get¶meter='+ key + skipCacheQuery, function(data, callback) {
|
||||
$.get('php/server/parameters.php?action=get¶meter='+ key + skipCacheQuery, function(data) {
|
||||
|
||||
var result = data;
|
||||
|
||||
@@ -415,8 +417,7 @@ CommitDB();
|
||||
result = result.replaceAll('"', '');
|
||||
}
|
||||
|
||||
document.getElementById(targetId).innerHTML = result;
|
||||
|
||||
document.getElementById(targetId).innerHTML = result.replaceAll('"', '');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -439,12 +440,13 @@ CommitDB();
|
||||
if(allOpen)
|
||||
{
|
||||
// close all
|
||||
$('.panel-collapse').each(function(){$(this).attr('class', 'panel-collapse collapse ')})
|
||||
$('div[data-myid="collapsible"]').each(function(){$(this).attr('class', 'panel-collapse collapse ')})
|
||||
$('#toggleSettings').attr('class', $('#toggleSettings').attr('class').replace(closeIcon, openIcon))
|
||||
}
|
||||
else{
|
||||
// open all
|
||||
$('.panel-collapse').each(function(){$(this).attr('class', 'panel-collapse collapse in')})
|
||||
$('div[data-myid="collapsible"]').each(function(){$(this).attr('class', 'panel-collapse collapse in')})
|
||||
$('div[data-myid="collapsible"]').each(function(){$(this).attr('style', 'height:inherit')})
|
||||
$('#toggleSettings').attr('class', $('#toggleSettings').attr('class').replace(openIcon, closeIcon))
|
||||
}
|
||||
|
||||
@@ -465,11 +467,44 @@ CommitDB();
|
||||
});
|
||||
});
|
||||
|
||||
function handleEvent (value){
|
||||
modalEventStatusId = 'modal-message-front-event'
|
||||
|
||||
function handleEvent (value){
|
||||
setParameter ('Front_Event', value)
|
||||
|
||||
// console.log(value)
|
||||
|
||||
// show message
|
||||
showModalOk("<?php echo lang("general_event_title")?>", "<?php echo lang("general_event_description")?> <code id='"+modalEventStatusId+"'></code>");
|
||||
|
||||
// Periodically update state of the requested action
|
||||
getParam(modalEventStatusId,"Front_Event", true, updateModalState)
|
||||
|
||||
updateModalState()
|
||||
}
|
||||
|
||||
|
||||
function updateModalState(){
|
||||
|
||||
setTimeout(function(){
|
||||
displayedEvent = $('#'+modalEventStatusId).html()
|
||||
|
||||
// console.log(displayedEvent)
|
||||
// console.log(displayedEvent.indexOf('finished') == -1)
|
||||
|
||||
// loop until finished
|
||||
if(displayedEvent.indexOf('finished') == -1) // if the message is different from finished, check again in 4s
|
||||
{
|
||||
|
||||
getParam(modalEventStatusId,"Front_Event", true)
|
||||
|
||||
updateModalState()
|
||||
|
||||
}
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// handling events on the backend initiated by the front end END
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user