@@ -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():
31623163def 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 ("\n Services 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%"> </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...' )
0 commit comments