Skip to content

Commit b9be7ce

Browse files
authored
Merge pull request #508 from leiweibau/next_update
Next update
2 parents 8a6d8ce + 3745ca8 commit b9be7ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2494
-751
lines changed

back/pialert-cli

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
SCRIPTVERSION='v1.33'
2+
SCRIPTVERSION='v1.35'
33
SCRIPT=$(readlink -f $0)
44
SCRIPTPATH=`dirname $SCRIPT`
55
PIA_CONF_FILE=${SCRIPTPATH}'/../config/pialert.conf'
@@ -715,6 +715,49 @@ EOM
715715
else
716716
echo " Column 'sat_conf_scan_asuswrt' already exists in the 'Satellites' table."
717717
fi
718+
# ICMP_Mon.icmp_vendor
719+
echo -e "...Insert new column 'icmp_vendor' to table 'ICMP_Mon' to DB"
720+
existing=$(sqlite3 $PIA_DB_FILE "PRAGMA table_info('ICMP_Mon');" | awk -F\| '{print $2}' | grep -wci "icmp_vendor")
721+
if [ $existing -eq 0 ]; then
722+
sqlite3 $PIA_DB_FILE "ALTER TABLE 'ICMP_Mon' ADD COLUMN 'icmp_vendor' STRING(100);"
723+
else
724+
echo " Column 'icmp_vendor' already exists in the 'ICMP_Mon' table."
725+
fi
726+
# ICMP_Mon.icmp_model
727+
echo -e "...Insert new column 'icmp_model' to table 'ICMP_Mon' to DB"
728+
existing=$(sqlite3 $PIA_DB_FILE "PRAGMA table_info('ICMP_Mon');" | awk -F\| '{print $2}' | grep -wci "icmp_model")
729+
if [ $existing -eq 0 ]; then
730+
sqlite3 $PIA_DB_FILE "ALTER TABLE 'ICMP_Mon' ADD COLUMN 'icmp_model' STRING(100);"
731+
else
732+
echo " Column 'icmp_model' already exists in the 'ICMP_Mon' table."
733+
fi
734+
# ICMP_Mon.icmp_serial
735+
echo -e "...Insert new column 'icmp_serial' to table 'ICMP_Mon' to DB"
736+
existing=$(sqlite3 $PIA_DB_FILE "PRAGMA table_info('ICMP_Mon');" | awk -F\| '{print $2}' | grep -wci "icmp_serial")
737+
if [ $existing -eq 0 ]; then
738+
sqlite3 $PIA_DB_FILE "ALTER TABLE 'ICMP_Mon' ADD COLUMN 'icmp_serial' STRING(25);"
739+
else
740+
echo " Column 'icmp_serial' already exists in the 'ICMP_Mon' table."
741+
fi
742+
# Services.mon_AlertUp
743+
echo -e "...Insert new column 'mon_AlertUp' to table 'Services' to DB"
744+
existing=$(sqlite3 $PIA_DB_FILE "PRAGMA table_info('Services');" | awk -F\| '{print $2}' | grep -wci "mon_AlertUp")
745+
if [ $existing -eq 0 ]; then
746+
sqlite3 $PIA_DB_FILE "ALTER TABLE 'Services' ADD COLUMN 'mon_AlertUp' INTEGER DEFAULT 0;"
747+
else
748+
echo " Column 'mon_AlertUp' already exists in the 'Services' table."
749+
fi
750+
# Services_CurrentScan.cur_AlertUp
751+
echo -e "...Insert new column 'cur_AlertUp' to table 'Services_CurrentScan' to DB"
752+
existing=$(sqlite3 $PIA_DB_FILE "PRAGMA table_info('Services_CurrentScan');" | awk -F\| '{print $2}' | grep -wci "cur_AlertUp")
753+
if [ $existing -eq 0 ]; then
754+
sqlite3 $PIA_DB_FILE "ALTER TABLE 'Services_CurrentScan' ADD COLUMN 'cur_AlertUp' INTEGER DEFAULT 0;"
755+
else
756+
echo " Column 'cur_AlertUp' already exists in the 'Services_CurrentScan' table."
757+
fi
758+
759+
760+
718761

719762
echo -e "\nUpdate finished!\n"
720763

back/pialert.py

Lines changed: 64 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2985,16 +2985,17 @@ def set_services_current_scan(_cur_URL, _cur_DateTime, _cur_StatusCode, _cur_Lat
29852985
sql.execute("SELECT * FROM Services WHERE mon_URL = ?", [_cur_URL])
29862986
rows = sql.fetchall()
29872987
for row in rows:
2988-
_mon_AlertEvents = row[6]
2989-
_mon_AlertDown = row[7]
2990-
_mon_StatusCode = row[2]
2991-
_mon_Latency = row[3]
2992-
_mon_TargetIP = row[8]
2993-
_mon_ssl_subject = row[10] # FC value 8
2994-
_mon_ssl_issuer = row[11] # FC value 4
2995-
_mon_ssl_valid_from = row[12] # FC value 2
2996-
_mon_ssl_valid_to = row[13] # FC value 1
2997-
_mon_ssl_fc = row[14] # FC value between 0 and 15
2988+
_mon_AlertEvents = row["mon_AlertEvents"]
2989+
_mon_AlertDown = row["mon_AlertDown"]
2990+
_mon_AlertUp = row["mon_AlertUp"]
2991+
_mon_StatusCode = row["mon_LastStatus"]
2992+
_mon_Latency = row["mon_LastLatency"]
2993+
_mon_TargetIP = row["mon_TargetIP"]
2994+
_mon_ssl_subject = row["mon_ssl_subject"]
2995+
_mon_ssl_issuer = row["mon_ssl_issuer"]
2996+
_mon_ssl_valid_from = row["mon_ssl_valid_from"]
2997+
_mon_ssl_valid_to = row["mon_ssl_valid_to"]
2998+
_mon_ssl_fc = row["mon_ssl_fc"]
29982999

29993000
# SSL Info change - Calc FC
30003001
if len(_cur_ssl_info) == 4:
@@ -3039,10 +3040,10 @@ def set_services_current_scan(_cur_URL, _cur_DateTime, _cur_StatusCode, _cur_Lat
30393040
StatusChanged = 1 if _cur_StatusChanged > 0 else 0
30403041

30413042
sqlite_insert = """INSERT INTO Services_CurrentScan
3042-
(cur_URL, cur_DateTime, cur_StatusCode, cur_Latency, cur_AlertEvents, cur_AlertDown, cur_StatusChanged, cur_LatencyChanged, cur_TargetIP, cur_StatusCode_prev, cur_TargetIP_prev, cur_ssl_subject, cur_ssl_issuer, cur_ssl_valid_from, cur_ssl_valid_to, cur_ssl_fc)
3043-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"""
3043+
(cur_URL, cur_DateTime, cur_StatusCode, cur_Latency, cur_AlertEvents, cur_AlertDown, cur_AlertUp, cur_StatusChanged, cur_LatencyChanged, cur_TargetIP, cur_StatusCode_prev, cur_TargetIP_prev, cur_ssl_subject, cur_ssl_issuer, cur_ssl_valid_from, cur_ssl_valid_to, cur_ssl_fc)
3044+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"""
30443045

3045-
table_data = (_cur_URL, _cur_DateTime, _cur_StatusCode, _cur_Latency, _mon_AlertEvents, _mon_AlertDown, StatusChanged, _cur_LatencyChanged, _cur_TargetIP, _mon_StatusCode, _mon_TargetIP, _cur_ssl_subject, _cur_ssl_issuer, _cur_ssl_valid_from, _cur_ssl_valid_to, _cur_ssl_fc)
3046+
table_data = (_cur_URL, _cur_DateTime, _cur_StatusCode, _cur_Latency, _mon_AlertEvents, _mon_AlertDown, _mon_AlertUp, StatusChanged, _cur_LatencyChanged, _cur_TargetIP, _mon_StatusCode, _mon_TargetIP, _cur_ssl_subject, _cur_ssl_issuer, _cur_ssl_valid_from, _cur_ssl_valid_to, _cur_ssl_fc)
30463047
sql.execute(sqlite_insert, table_data)
30473048
sql_connection.commit()
30483049

@@ -3162,14 +3163,17 @@ def flush_services_current_scan():
31623163
def print_service_monitoring_changes():
31633164

31643165
print(" Services Monitoring Changes...")
3165-
changedStatusCode = sql.execute("SELECT COUNT() FROM Services_CurrentScan WHERE cur_StatusChanged = 1").fetchone()[0]
3166-
print(" Changed StatusCodes.....:", str(changedStatusCode))
3167-
changedLatency = sql.execute("SELECT COUNT() FROM Services_CurrentScan WHERE cur_LatencyChanged = 1").fetchone()[0]
3168-
print(" Changed Reachability....:", str(changedLatency))
3166+
changedStatusCode = sql.execute("SELECT COUNT() FROM Services_CurrentScan WHERE cur_StatusChanged = 1 AND cur_Latency != 99999999").fetchone()[0]
3167+
print(" StatusCodes...:", str(changedStatusCode))
3168+
changeddown = sql.execute("SELECT COUNT() FROM Services_CurrentScan WHERE cur_LatencyChanged = 1").fetchone()[0]
3169+
print(" Down..........:", str(changeddown))
3170+
changedup = sql.execute("SELECT COUNT() FROM Services_CurrentScan WHERE cur_StatusChanged = 1 AND cur_StatusCode_prev = 0 AND cur_StatusCode = 200").fetchone()[0]
3171+
print(" Up............:", str(changedup))
31693172
with open(PIALERT_WEBSERVICES_LOG, 'a') as monitor_logfile:
31703173
monitor_logfile.write("\nServices Monitoring Changes:\n")
3171-
monitor_logfile.write(" Changed StatusCodes.....: " + str(changedStatusCode))
3172-
monitor_logfile.write("\n Changed Reachability....: " + str(changedLatency))
3174+
monitor_logfile.write(" StatusCodes...: " + str(changedStatusCode))
3175+
monitor_logfile.write("\n Down..........: " + str(changeddown))
3176+
monitor_logfile.write("\n Up............: " + str(changedup))
31733177
monitor_logfile.write("\n")
31743178
monitor_logfile.close()
31753179

@@ -3203,7 +3207,7 @@ def service_monitoring_notification():
32033207
html_line_template = '<tr bgcolor=#909090 style="color:#F0F0F0;"><td colspan="2" style="width:50%; font-size:1.2em;"><b>URL:</b> {} </td><td colspan="2" style="width:50%; font-size:1.2em;"><b>Tag:</b> {} </td></tr>\n'+ \
32043208
'<tr><td colspan="2" style="width:50%"><b>ScanTime:</b> {} </td><td style="width:25%"><b>IP:</b> {} </td><td style="width:25%"><b>prev. IP:</b> {} </td></tr>\n'
32053209

3206-
sql.execute ("""SELECT Services_CurrentScan.*, Services.mon_tags
3210+
sql.execute ("""SELECT Services_CurrentScan.*, Services.mon_Tags
32073211
FROM Services_CurrentScan
32083212
JOIN Services ON Services_CurrentScan.cur_URL = Services.mon_URL
32093213
WHERE Services_CurrentScan.cur_AlertDown = 1
@@ -3223,16 +3227,50 @@ def service_monitoring_notification():
32233227
mail_section_services_down = True
32243228
mail_text_services_down += text_line_template.format (
32253229
'Service: ', eventAlert['cur_URL'],
3226-
'Tag: ', eventAlert['mon_tags'],
3230+
'Tag: ', eventAlert['mon_Tags'],
32273231
'Time: ', eventAlert['cur_DateTime'],
32283232
'Destination IP: ', _func_cur_TargetIP,
32293233
'prev. Destination IP: ', _func_cur_TargetIP_prev)
32303234
mail_html_services_down += html_line_template.format (
3231-
eventAlert['cur_URL'], eventAlert['mon_tags'], eventAlert['cur_DateTime'], _func_cur_TargetIP, _func_cur_TargetIP_prev)
3235+
eventAlert['cur_URL'], eventAlert['mon_Tags'], eventAlert['cur_DateTime'], _func_cur_TargetIP, _func_cur_TargetIP_prev)
32323236

32333237
format_report_section_services (mail_section_services_down, 'SECTION_DEVICES_DOWN',
32343238
'TABLE_DEVICES_DOWN', mail_text_services_down, mail_html_services_down)
32353239

3240+
3241+
# # Compose Devices Up Section
3242+
mail_section_services_up = False
3243+
mail_text_services_up = ''
3244+
mail_html_services_up = ''
3245+
text_line_template = '{}{}\n\t{}\t\t\t{}\n\t{}\t\t\t{}\n\t{}\t{}\n\n'
3246+
html_line_template = '<tr bgcolor=#909090 style="color:#F0F0F0;"><td colspan="2" style="width:50%; font-size:1.2em;"><b>URL:</b> {} </td><td colspan="2" style="width:50%; font-size:1.2em;"><b>Tag:</b> {} </td></tr>\n'+ \
3247+
'<tr><td colspan="2" style="width:50%"><b>ScanTime:</b> {} </td><td style="width:25%"><b>IP:</b> {} </td></tr>\n'
3248+
3249+
sql.execute ("""SELECT Services_CurrentScan.*, Services.mon_Tags
3250+
FROM Services_CurrentScan
3251+
JOIN Services ON Services_CurrentScan.cur_URL = Services.mon_URL
3252+
WHERE Services_CurrentScan.cur_AlertUp = 1
3253+
AND Services_CurrentScan.cur_StatusChanged = 1
3254+
AND Services_CurrentScan.cur_StatusCode = 200
3255+
AND Services_CurrentScan.cur_StatusCode_prev = 0
3256+
ORDER BY Services_CurrentScan.cur_DateTime""")
3257+
3258+
for eventAlert in sql :
3259+
mail_section_services_up = True
3260+
mail_text_services_up += text_line_template.format (
3261+
'Service: ', eventAlert['cur_URL'],
3262+
'Tag: ', eventAlert['mon_Tags'],
3263+
'Time: ', eventAlert['cur_DateTime'],
3264+
'Destination IP: ', eventAlert['cur_TargetIP'])
3265+
mail_html_services_up += html_line_template.format (
3266+
eventAlert['cur_URL'], eventAlert['mon_Tags'], eventAlert['cur_DateTime'], eventAlert['cur_TargetIP'])
3267+
3268+
print(mail_text_services_up)
3269+
3270+
format_report_section_services (mail_section_services_up, 'SECTION_DEVICES_UP',
3271+
'TABLE_DEVICES_UP', mail_text_services_up, mail_html_services_up)
3272+
3273+
32363274
# Compose Events Section (includes Down as an Event)
32373275
mail_section_events = False
32383276
mail_text_events = ''
@@ -3242,7 +3280,7 @@ def service_monitoring_notification():
32423280
'<tr><td style="width:25%"><b>ScanTime:</b> {} </td> <td style="width:25%"><b>IP:</b> {} </td> <td style="width:25%"><b>prev. IP:</b> {} </td> <td style="width:25%"><b>Latency:</b> {} </td> <tr>\n'+ \
32433281
'<tr><td style="width:25%">&nbsp;</td> <td style="width:25%"><b>StatusCode:</b> {} </td> <td style="width:25%"><b>prev. StatusCode:</b> {} </td> <td style="width:25%"><b>SSL Code:</b> {} </td> </tr>\n'
32443282

3245-
sql.execute ("""SELECT Services_CurrentScan.*, Services.mon_tags
3283+
sql.execute ("""SELECT Services_CurrentScan.*, Services.mon_Tags
32463284
FROM Services_CurrentScan
32473285
JOIN Services ON Services_CurrentScan.cur_URL = Services.mon_URL
32483286
WHERE Services_CurrentScan.cur_AlertEvents = 1
@@ -3262,23 +3300,23 @@ def service_monitoring_notification():
32623300
mail_section_events = True
32633301
mail_text_events += text_line_template.format (
32643302
'Service: ', eventAlert['cur_URL'],
3265-
'Tag: ', eventAlert['mon_tags'],
3303+
'Tag: ', eventAlert['mon_Tags'],
32663304
'Time: ', eventAlert['cur_DateTime'],
32673305
'Destination IP: ', _func_cur_TargetIP,
32683306
'prev. Destination IP: ', _func_cur_TargetIP_prev,
32693307
'HTTP Status Code: ', eventAlert['cur_StatusCode'],
32703308
'prev. HTTP Status Code: ', eventAlert['cur_StatusCode_prev'],
32713309
'SSL Status: ', eventAlert['cur_ssl_fc'])
32723310
mail_html_events += html_line_template.format (
3273-
eventAlert['cur_URL'], eventAlert['mon_tags'],
3311+
eventAlert['cur_URL'], eventAlert['mon_Tags'],
32743312
eventAlert['cur_DateTime'], _func_cur_TargetIP, _func_cur_TargetIP_prev, eventAlert['cur_Latency'],
32753313
eventAlert['cur_StatusCode'], eventAlert['cur_StatusCode_prev'], eventAlert['cur_ssl_fc'])
32763314

32773315
format_report_section_services (mail_section_events, 'SECTION_EVENTS',
32783316
'TABLE_EVENTS', mail_text_events, mail_html_events)
32793317

32803318
# # Send Mail
3281-
if mail_section_services_down == True or mail_section_events == True :
3319+
if mail_section_services_down == True or mail_section_events == True or mail_section_services_up == True:
32823320
sending_notifications ('webservice', mail_html_webservice, mail_text_webservice)
32833321
else :
32843322
print(' No changes to report...')

back/report_template_webservice.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@
5656
<br>
5757
</SECTION_DEVICES_DOWN>
5858

59+
<SECTION_DEVICES_UP>
60+
<p style="font-size: 14px; font-weight: bold; color:#C04040"> Services Down: </p>
61+
62+
<table width=100% border=1 bordercolor=#C0C0C0 cellpadding=3px cellspacing=0 style="border-collapse: collapse; font-size: 12px; color:#707070">
63+
<TABLE_DEVICES_UP>
64+
</table>
65+
66+
<br>
67+
</SECTION_DEVICES_UP>
68+
5969
<SECTION_EVENTS>
6070
<p style="font-size: 14px; font-weight: bold; color:#409040"> Services Events: </p>
6171

back/report_template_webservice.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ Server: <SERVER_NAME>
55
Services Down
66
------------------------------
77
<TABLE_DEVICES_DOWN>
8-
</SECTION_DEVICES_DOWN><SECTION_EVENTS>Services Events
8+
</SECTION_DEVICES_DOWN><SECTION_DEVICES_UP>
9+
Services Up
10+
------------------------------
11+
<TABLE_DEVICES_UP>
12+
</SECTION_DEVICES_UP><SECTION_EVENTS>
13+
Services Events
914
------------------------------
1015
<TABLE_EVENTS>
1116
</SECTION_EVENTS>

0 commit comments

Comments
 (0)