Email notification update off monitor device

Support questions about the Threshold plugin

Moderators: Developers, Moderators

User avatar
dragossto
Cacti User
Posts: 86
Joined: Tue May 15, 2007 5:24 am
Location: Romania
Contact:

Email notification update off monitor device

Post by dragossto »

update to latest svn from date 28.09.2011

support to disable email per host
possibility to add extra email for up/down notification for specific host
the option it available when edit host (device)

different message for up and down host (under setting , category thold )
add prio under setting thold
and few extra message body options

All these changes have been added to new svn

to update from
0.4.6 to 0.4.7
have to execute under linux server this command

Code: Select all

mysql -e "ALTER TABLE host MODIFY thold_send_email int(10) DEFAULT '1'" cacti
mysql -e "update host set thold_send_email='1'" cacti
to update to 0.4.8 have to have on your system cacti 0.8.7h and PIA 3.0
and apply patched file inside Ugroup before install plugin Ugroup


Latest modification:
svn thold 0.4.7.zip
update 14.10.2011
(123.56 KiB) Downloaded 334 times
Attachments
svn thold 0.4.8.zip
update 19.10.2011
(143.08 KiB) Downloaded 390 times
Last edited by dragossto on Tue Oct 18, 2011 4:51 pm, edited 10 times in total.
User avatar
dragossto
Cacti User
Posts: 86
Joined: Tue May 15, 2007 5:24 am
Location: Romania
Contact:

Post by dragossto »

starting from this thread
http://forums.cacti.net/about16837.html ... ost+Notice

i add some new info to email report about
up , or down notifications

i don't know if it work whit version 4.3
because few moths ago i update my version of thold
from http://svn.cacti.net/viewvc/thold/branc ... ot=Plugins

the new email notification wheel look like this :
Host Notice : Cacti_Name (Host_ip) returned from DOWN state
System Availability : 99.30229
Average (ms) response time 0.50251 , Current (ms) response time 1.39450

SNMP Info :
System:.....
Uptime: 47195293(5 days, 11 hours, 5 minutes)
Hostname: .....
Location: .....
Contact: .....
.

Host had been down for 3 minutes, 19 seconds since 2010-02-25 02:00:13.
like SNMP Info from editing device wheel be seen just when the
Downed Device Detection it set to Snmp detection whit , without or icmp ping

and the down message look like this
Host Error : Cacti_Name (Host_ip) is DOWN
Message : SNMP not performed due to setting or ping result., ICMP ping Timed out.

Host had been up for 2 hours, 54 minutes, 37 seconds since 2010-02-24 23:13:07.
this it a update ho work with
Cacti 0.8.7g
P.A. 2.9
thold version 0.5

both updated from
svn cacti plugins
linux user :
P.A.

Code: Select all

svn co svn://svn.cacti.net/cacti/PIA
Thold

Code: Select all

svn co svn://svn.cacti.net/cacti_plugins/thold
Last edited by dragossto on Sun Feb 20, 2011 7:43 pm, edited 1 time in total.
cigamit
Developer
Posts: 3367
Joined: Thu Apr 07, 2005 3:29 pm
Location: B/CS Texas
Contact:

Re: Email notification update off monitor device

Post by cigamit »

Can you create me a diff? I will see about getting this put into stable.
User avatar
dragossto
Cacti User
Posts: 86
Joined: Tue May 15, 2007 5:24 am
Location: Romania
Contact:

Re: Email notification update off monitor device

Post by dragossto »

i will try ,even it first time i make one :)
Cacti - 0.8.7h
Plugin Architecture - 3.0
Poller Type - SPINE 0.8.7g
Server Info - Linux 2.6.35.10 - Slackware 13.1
Web Server - Apache/2.2.17 (Unix) DAV/2 PHP 5.3.5
MySQL - 5.1.53 ;RRDTool - 1.4.5 ;SNMP - 5.6.1
Plugins
  • (tools - v0.3) (Thold - v0.4.6) (Ntop - v0.2) (Discovery - v1.2a) (Monitor - v1.2)
User avatar
dragossto
Cacti User
Posts: 86
Joined: Tue May 15, 2007 5:24 am
Location: Romania
Contact:

Re: Email notification update off monitor device

Post by dragossto »

hear it is
using command
diff -Naur newpolling.php originalpolling.php >> polling.php.diff

Code: Select all

--- new polling.php	2010-09-26 16:09:52.000000000 +0300
+++ original polling.php	2010-09-26 00:09:42.000000000 +0300
@@ -22,7 +22,6 @@
  | http://www.cacti.net/                                                   |
  +-------------------------------------------------------------------------+
 */
-include_once($config['library_path'] . '/snmp.php');
 
 function thold_poller_bottom () {
 	/* record the start time */
@@ -146,7 +145,7 @@
 						$currentval = round($currentval, 4);
 						break;
 				}
-
+
 				db_execute("UPDATE thold_data SET tcheck = 1, lastread = '$currentval', oldvalue = '" . $item[$t_item['name']] . "' WHERE rra_id = " . $t_item['rra_id'] . " AND data_id = " . $t_item['data_id']);
 			}
 		}
@@ -185,72 +184,13 @@
 	if (!empty($failed)) {
 		foreach($failed as $id) {
 			if ($id != '') {
-				$host = db_fetch_row('SELECT id, status, description, hostname, snmp_community, snmp_username, snmp_password, snmp_version, snmp_auth_protocol, snmp_priv_passphrase, snmp_priv_protocol, snmp_context, snmp_port, snmp_timeout, status_fail_date, availability, avg_time, cur_time FROM host WHERE id = ' . $id);
+				$host = db_fetch_row('SELECT id, status, description, hostname FROM host WHERE id = ' . $id);
 				if ($host['status'] == HOST_UP) {
 					$subject = 'Host Notice : ' . $host['description'] . ' (' . $host['hostname'] . ') returned from DOWN state';
-					$msg = $subject . '<br>System Availability : ' . $host['availability'] . ' <br>Average (ms) response time ' . $host['avg_time']  . ' , Current (ms) response time ' . $host['cur_time'] . ' <br><br>SNMP Info : <br>';
-					if ((($host["snmp_community"] == "") && ($host["snmp_username"] == "")) || ($host["snmp_version"] == 0)) {
-						$msg = $msg . 'SNMP not in use';
-					}else{
-						$snmp_system = cacti_snmp_get($host['hostname'], $host['snmp_community'], ".1.3.6.1.2.1.1.1.0", $host['snmp_version'],
-						    $host['snmp_username'], $host['snmp_password'],
-						    $host['snmp_auth_protocol'], $host['snmp_priv_passphrase'], $host['snmp_priv_protocol'],
-						    $host['snmp_context'], $host['snmp_port'], $host['snmp_timeout'], read_config_option("snmp_retries"), SNMP_WEBUI);
-						if (substr_count($snmp_system, "00:")) {
-						    $snmp_system = str_replace("00:", "", $snmp_system);
-						    $snmp_system = str_replace(":", " ", $snmp_system);
-						}
-						if ($snmp_system == "") {
-						    $msg = $msg . 'SNMP error';
-						}else{
-						    $snmp_uptime   = cacti_snmp_get($host['hostname'], $host['snmp_community'], ".1.3.6.1.2.1.1.3.0", $host['snmp_version'],
-							$host['snmp_username'], $host['snmp_password'],
-							$host['snmp_auth_protocol'], $host['snmp_priv_passphrase'], $host['snmp_priv_protocol'],
-							$host['snmp_context'], $host['snmp_port'], $host['snmp_timeout'], read_config_option("snmp_retries"), SNMP_WEBUI);
-						    $snmp_hostname = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.5.0", $host["snmp_version"],
-							$host["snmp_username"], $host["snmp_password"],
-							$host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"],
-							$host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI);
-						    $snmp_location = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.6.0", $host["snmp_version"],
-							$host["snmp_username"], $host["snmp_password"],
-							$host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"],
-							$host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI);
-						    $snmp_contact  = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.4.0", $host["snmp_version"],
-							$host["snmp_username"], $host["snmp_password"],
-							$host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"],
-							$host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI);
-						    $msg = $msg . "System:" . html_split_string($snmp_system) . "<br>";
-						    $days      = intval($snmp_uptime / (60*60*24*100));
-						    $remainder = $snmp_uptime % (60*60*24*100);
-						    $hours     = intval($remainder / (60*60*100));
-						    $remainder = $remainder % (60*60*100);
-						    $minutes   = intval($remainder / (60*100));
-						    $msg = $msg . "Uptime: $snmp_uptime";
-						    $msg = $msg . "($days days, $hours hours, $minutes minutes)<br>";
-						    $msg = $msg . "Hostname: $snmp_hostname<br>";
-						    $msg = $msg . "Location: $snmp_location<br>";
-						    $msg = $msg . "Contact: $snmp_contact<br>";
-						}
+					$msg = $subject;
+					if ($logset) {
+						plugin_thold_syslog_host_status($subject);
 					}
-					$downtime = time() - strtotime($host['status_fail_date']);
-					$downtime_days = floor($downtime/86400);
-					$downtime_hours = floor(($downtime - ($downtime_days * 86400))/3600);
-					$downtime_minutes = floor(($downtime - ($downtime_days * 86400) - ($downtime_hours * 3600))/60);
-					$downtime_seconds = $downtime - ($downtime_days * 86400) - ($downtime_hours * 3600) - ($downtime_minutes * 60);
-					$msg = $msg . ".<br><br>Host had been down for ";
-					if ($downtime_days > 0 ) {
-					    $msg = $msg . $downtime_days . " days, " . $downtime_hours . " hours, " . $downtime_minutes . " minutes, " . $downtime_seconds . " seconds ";
-					} elseif ($downtime_hours > 0 ) {
-					    $msg = $msg . $downtime_hours . " hours, " . $downtime_minutes . " minutes, " . $downtime_seconds . " seconds ";
-					} elseif ($downtime_minutes > 0 ) {
-					    $msg = $msg . $downtime_minutes . " minutes, " . $downtime_seconds . " seconds ";
-					} else {
-					    $msg = $msg . $downtime_seconds . " seconds ";
-					}
-					$msg = $msg . "since " . $host["status_fail_date"] . ".";
-//					if ($logset) {
-//						plugin_thold_syslog_host_status($subject);
-//					}
 					if ($alert_email == '') {
 						cacti_log('THOLD: Can not send Host Recovering email since the \'Alert e-mail\' setting is not set!', true, 'POLLER');
 					} else {
@@ -262,31 +202,15 @@
 	}
 
 	// Lets find hosts that are down
-	$hosts = db_fetch_assoc('SELECT id, description, hostname, status_last_error, status_rec_date FROM host WHERE disabled="" AND status=' . HOST_DOWN . ' AND status_event_count=' . $ping_failure_count);
+	$hosts = db_fetch_assoc('SELECT id, description, hostname, status_last_error FROM host WHERE disabled="" AND status=' . HOST_DOWN . ' AND status_event_count=' . $ping_failure_count);
 	$total_hosts = sizeof($hosts);
 	if (count($hosts)) {
 		foreach($hosts as $host) {
 			$subject = 'Host Error : ' . $host['description'] . ' (' . $host['hostname'] . ') is DOWN';
 			$msg = 'Host Error : ' . $host['description'] . ' (' . $host['hostname'] . ') is DOWN<br>Message : ' . $host['status_last_error'];
-			$downtime = time() - strtotime($host['status_rec_date']);
-			$downtime_days = floor($downtime/86400);
-			$downtime_hours = floor(($downtime - ($downtime_days * 86400))/3600);
-			$downtime_minutes = floor(($downtime - ($downtime_days * 86400) - ($downtime_hours * 3600))/60);
-			$downtime_seconds = $downtime - ($downtime_days * 86400) - ($downtime_hours * 3600) - ($downtime_minutes * 60);
-			$msg = $msg . ".<br><br>Host had been up for ";
-			if ($downtime_days > 0 ) {
-			    $msg = $msg . $downtime_days . " days, " . $downtime_hours . " hours, " . $downtime_minutes . " minutes, " . $downtime_seconds . " seconds ";
-			} elseif ($downtime_hours > 0 ) {
-			    $msg = $msg . $downtime_hours . " hours, " . $downtime_minutes . " minutes, " . $downtime_seconds . " seconds ";
-			} elseif ($downtime_minutes > 0 ) {
-			    $msg = $msg . $downtime_minutes . " minutes, " . $downtime_seconds . " seconds ";
-			} else {
-			    $msg = $msg . $downtime_seconds . " seconds ";
+			if ($logset) {
+				plugin_thold_syslog_host_status($subject);
 			}
-			$msg = $msg . "since " . $host['status_rec_date'] . ".";
-//			if ($logset) {
-//				plugin_thold_syslog_host_status($subject);
-//			}
 			if ($alert_email == '') {
 				cacti_log('THOLD: Can not send Host Down email since the \'Alert e-mail\' setting is not set!', true, 'POLLER');
 			} else {
Attachments
polling.php.diff.zip
the result file
(2.04 KiB) Downloaded 294 times
Cacti - 0.8.7h
Plugin Architecture - 3.0
Poller Type - SPINE 0.8.7g
Server Info - Linux 2.6.35.10 - Slackware 13.1
Web Server - Apache/2.2.17 (Unix) DAV/2 PHP 5.3.5
MySQL - 5.1.53 ;RRDTool - 1.4.5 ;SNMP - 5.6.1
Plugins
  • (tools - v0.3) (Thold - v0.4.6) (Ntop - v0.2) (Discovery - v1.2a) (Monitor - v1.2)
cigamit
Developer
Posts: 3367
Joined: Thu Apr 07, 2005 3:29 pm
Location: B/CS Texas
Contact:

Re: Email notification update off monitor device

Post by cigamit »

Thats actually a reverse diff, but since I am putting it in my hand, it doesn't matter to me. I will probably throw in an option under Settings to allow you to customize it exactly how you want (just like the threshold email) but it will default to almost exactly how you have it now.
User avatar
dragossto
Cacti User
Posts: 86
Joined: Tue May 15, 2007 5:24 am
Location: Romania
Contact:

Re: Email notification update off monitor device

Post by dragossto »

10x for yours effort
to add them to default stable version

i fink this it important information that are already in cacti
and it possible to be handy to others
not just to me :)

i use this command because i don't find other in cacti forum

Have a nice day
Cacti - 0.8.7h
Plugin Architecture - 3.0
Poller Type - SPINE 0.8.7g
Server Info - Linux 2.6.35.10 - Slackware 13.1
Web Server - Apache/2.2.17 (Unix) DAV/2 PHP 5.3.5
MySQL - 5.1.53 ;RRDTool - 1.4.5 ;SNMP - 5.6.1
Plugins
  • (tools - v0.3) (Thold - v0.4.6) (Ntop - v0.2) (Discovery - v1.2a) (Monitor - v1.2)
User avatar
dragossto
Cacti User
Posts: 86
Joined: Tue May 15, 2007 5:24 am
Location: Romania
Contact:

Re: Email notification update off monitor device

Post by dragossto »

the first post contain the modification

the subject for down

Code: Select all

Host Error: <DESCRIPTION> (<HOSTNAME>) is DOWN
the message for down

Code: Select all

System Error : <DESCRIPTION> (<HOSTNAME>) is <DOWN/UP><br>Reason: <MESSAGE><br><br>Average system response : <AVG_TIME> ms<br>System availability: <AVAILABILITY><br>Last date going DOWN : <LAST_FAIL><br>Host had been up for: <DOWNTIME><br>NOTE: <NOTES>
the subject for up

Code: Select all

Host Notice: <DESCRIPTION> (<HOSTNAME>) returned from DOWN state
the message for up

Code: Select all

Host: <DESCRIPTION> (<HOSTNAME>) returned from DOWN state<br> System status: <DOWN/UP><br><br>Current ping response: <CUR_TIME> ms<br>Average system response : <AVG_TIME> ms<br>System availability: <AVAILABILITY><br>Last time see system UP: <LAST_FAIL><br>Host had been down for: <DOWNTIME><br><br>Snmp Info:<br>Name - <SNMP_HOSTNAME><br>Location - <SNMP_LOCATION><br>Uptime - <UPTIMETEXT> (<UPTIME> ms)<br>System - <SNMP_SYSTEM><br><br>NOTE: <NOTES>
Attachments
.<br />___________________Under setting <br />_________________Category Thold
.
___________________Under setting
_________________Category Thold
Setting for subject and mesaage.JPG (104.26 KiB) Viewed 18416 times
.<br />____________________Under Device<br />__________________When edit host
.
____________________Under Device
__________________When edit host
Email Option for Host.JPG (17.92 KiB) Viewed 18416 times
Cacti - 0.8.7h
Plugin Architecture - 3.0
Poller Type - SPINE 0.8.7g
Server Info - Linux 2.6.35.10 - Slackware 13.1
Web Server - Apache/2.2.17 (Unix) DAV/2 PHP 5.3.5
MySQL - 5.1.53 ;RRDTool - 1.4.5 ;SNMP - 5.6.1
Plugins
  • (tools - v0.3) (Thold - v0.4.6) (Ntop - v0.2) (Discovery - v1.2a) (Monitor - v1.2)
User avatar
dragossto
Cacti User
Posts: 86
Joined: Tue May 15, 2007 5:24 am
Location: Romania
Contact:

Re: Email notification update off monitor device

Post by dragossto »

One extra setting in the message body
add the total count of polling for one host/device

Code: Select all

<TOT_POLL>
and the total fails count of polling for one host/device

Code: Select all

<FAIL_POLL>
the new message body for email up it
<br>System <DESCRIPTION> (<HOSTNAME>) status: <DOWN/UP><br><br>Current ping response: <CUR_TIME> ms<br>Average system response : <AVG_TIME> ms<br>System availability: <AVAILABILITY><br>System total pollings check: <TOT_POLL><br>System failds pollings check: <FAIL_POLL><br>Last time see system UP: <LAST_FAIL><br>Host had been down for: <DOWNTIME><br><br>Snmp Info:<br>Name - <SNMP_HOSTNAME><br>Location - <SNMP_LOCATION><br>Uptime - <UPTIMETEXT> (<UPTIME> ms)<br>System - <SNMP_SYSTEM><br><br>NOTE: <NOTES>
and the message body for email down it
System Error : <DESCRIPTION> (<HOSTNAME>) is <DOWN/UP><br>Reason: <MESSAGE><br><br>Average system response : <AVG_TIME> ms<br>System availability: <AVAILABILITY><br>System total pollings check: <TOT_POLL><br>System failds pollings check: <FAIL_POLL><br>Last date going DOWN : <LAST_FAIL><br>Host had been up for: <DOWNTIME><br>NOTE: <NOTES>
the new code it download able from the first post
Cacti - 0.8.7h
Plugin Architecture - 3.0
Poller Type - SPINE 0.8.7g
Server Info - Linux 2.6.35.10 - Slackware 13.1
Web Server - Apache/2.2.17 (Unix) DAV/2 PHP 5.3.5
MySQL - 5.1.53 ;RRDTool - 1.4.5 ;SNMP - 5.6.1
Plugins
  • (tools - v0.3) (Thold - v0.4.6) (Ntop - v0.2) (Discovery - v1.2a) (Monitor - v1.2)
thinice
Posts: 1
Joined: Wed Apr 06, 2011 3:39 pm

Re: Email notification update off monitor device

Post by thinice »

Say, on an unrelated note but maybe not worthy of it's own discussion - perhaps threshold alerts should be given X-Priority: 1 headers for importance toggle?

It's probably something that should be configurable, but for those who want it; apply this diff to the current svn stable:

Code: Select all

--- thold_functions.php	2011-04-06 15:37:27.000000000 -0500
@@ -1952,7 +1952,8 @@
 	$v = thold_version();
 	$Mailer->header_set('X-Mailer', 'Cacti-Thold-v' . $v['version']);
 	$Mailer->header_set('User-Agent', 'Cacti-Thold-v' . $v['version']);
-
+	$Mailer->header_set('X-Priority', '1');
+	
 	if ($Mailer->send($text) == false) {
 		print 'ERROR: ' . $Mailer->error() . "\n";
 		return $Mailer->error();
User avatar
dragossto
Cacti User
Posts: 86
Joined: Tue May 15, 2007 5:24 am
Location: Romania
Contact:

Re: Email notification update off monitor device

Post by dragossto »

add new thold whit modification
new changes hear
http://svn.cacti.net/viewvc/thold/branc ... iew=markup
no changes , only
remove from svn the annoying ^M
whit a command like this :

Code: Select all

allfile=`ls * -d -l|awk '{if(substr($0,0,1) == "-" )print $9}'`;for file in $allfile; do cat $file|tr -d "\015" >> $file".new";> $file;cat $file".new" >> $file;rm $file".new";done
and keep all the option posted previous

the part whit Thresholds, not tested.
my modification affect only the emails whit up and down notification.

thinice , for the moment i don't add your suggestion
i will add them under setting option.
Cacti - 0.8.7h
Plugin Architecture - 3.0
Poller Type - SPINE 0.8.7g
Server Info - Linux 2.6.35.10 - Slackware 13.1
Web Server - Apache/2.2.17 (Unix) DAV/2 PHP 5.3.5
MySQL - 5.1.53 ;RRDTool - 1.4.5 ;SNMP - 5.6.1
Plugins
  • (tools - v0.3) (Thold - v0.4.6) (Ntop - v0.2) (Discovery - v1.2a) (Monitor - v1.2)
beenpricked
Posts: 6
Joined: Tue Sep 20, 2011 5:35 pm

Re: Email notification update off monitor device

Post by beenpricked »

thinice wrote:Say, on an unrelated note but maybe not worthy of it's own discussion - perhaps threshold alerts should be given X-Priority: 1 headers for importance toggle?

It's probably something that should be configurable, but for those who want it; apply this diff to the current svn stable:

Code: Select all

--- thold_functions.php	2011-04-06 15:37:27.000000000 -0500
@@ -1952,7 +1952,8 @@
 	$v = thold_version();
 	$Mailer->header_set('X-Mailer', 'Cacti-Thold-v' . $v['version']);
 	$Mailer->header_set('User-Agent', 'Cacti-Thold-v' . $v['version']);
-
+	$Mailer->header_set('X-Priority', '1');
+	
 	if ($Mailer->send($text) == false) {
 		print 'ERROR: ' . $Mailer->error() . "\n";
 		return $Mailer->error();
Thinice,

I like this idea, wondering what we need to do to put it on to action. There are so many ways to track information that sometimes we forget how to program the ways to do it. For example, have you guys ever heard of webtrends, I know they have all kinds of crazy analytical tools.
Last edited by beenpricked on Sat Oct 01, 2011 7:19 pm, edited 1 time in total.
User avatar
dragossto
Cacti User
Posts: 86
Joined: Tue May 15, 2007 5:24 am
Location: Romania
Contact:

Re: Email notification update off monitor device

Post by dragossto »

I will add this , but for the moment , don't have time
from some time still hope to be able to have time
to update to new svn and add this option ,
but it better the user to have possibility to chose ,
so have to make some modification in setting .

good to sher to others your idea
Have a nice weekend.
Cacti - 0.8.7h
Plugin Architecture - 3.0
Poller Type - SPINE 0.8.7g
Server Info - Linux 2.6.35.10 - Slackware 13.1
Web Server - Apache/2.2.17 (Unix) DAV/2 PHP 5.3.5
MySQL - 5.1.53 ;RRDTool - 1.4.5 ;SNMP - 5.6.1
Plugins
  • (tools - v0.3) (Thold - v0.4.6) (Ntop - v0.2) (Discovery - v1.2a) (Monitor - v1.2)
User avatar
dragossto
Cacti User
Posts: 86
Joined: Tue May 15, 2007 5:24 am
Location: Romania
Contact:

Re: Email notification update off monitor device

Post by dragossto »

Diff between stable and this version 0.4.6
setup.php

Code: Select all

--- setup.php   
+++ /modif/setup.php       
@@ -29,6 +29,7 @@
        api_plugin_register_hook('thold', 'top_graph_header_tabs', 'thold_show_tab', 'includes/tab.php');
        api_plugin_register_hook('thold', 'config_insert', 'thold_config_insert', 'includes/settings.php');
        api_plugin_register_hook('thold', 'config_arrays', 'thold_config_arrays', 'includes/settings.php');
+       api_plugin_register_hook('thold', 'config_form', 'thold_config_form', 'includes/settings.php');
        api_plugin_register_hook('thold', 'config_settings', 'thold_config_settings', 'includes/settings.php');
        api_plugin_register_hook('thold', 'draw_navigation_text', 'thold_draw_navigation_text', 'includes/settings.php');
        api_plugin_register_hook('thold', 'data_sources_table', 'thold_data_sources_table', 'setup.php');
@@ -275,6 +276,14 @@
                }
                $result = db_execute($sql);
        }
+       if (isset($_POST['thold_send_email']))
+               $save['thold_send_email'] = form_input_validate($_POST['thold_send_email'], 'thold_send_email', '', true, 3);
+       else
+               $save['thold_send_email'] = form_input_validate('', 'thold_send_email', '', true, 3);
+       if (isset($_POST['thold_host_email']))
+               $save['thold_host_email'] = form_input_validate($_POST['thold_host_email'], 'thold_host_email', '', true, 3);
+       else
+               $save['thold_host_email'] = form_input_validate('', 'thold_host_email', '', true, 3);
        return $save;
 }
thold_functions.php

Code: Select all

--- thold_functions.php 
+++ /modif/thold_functions.php     
@@ -2667,6 +2667,9 @@
        $v = thold_version();
        $Mailer->header_set('X-Mailer', 'Cacti-Thold-v' . $v['version']);
        $Mailer->header_set('User-Agent', 'Cacti-Thold-v' . $v['version']);
+       if (read_config_option('thold_email_prio') == 'on') {
+               $Mailer->header_set('X-Priority', '1');
+       }
        thold_debug("Sending email to '" . trim(implode(',',$to),',') . "'");
        if ($Mailer->send($text) == false) {
includes/settings.php

Code: Select all

--- includes/settings.php        
+++ /modif/includes/settings.php   
@@ -72,6 +72,36 @@
        }
 }

+function thold_config_form () {
+       global $fields_host_edit;
+       $fields_host_edit2 = $fields_host_edit;
+       $fields_host_edit3 = array();
+       foreach ($fields_host_edit2 as $f => $a) {
+               $fields_host_edit3[$f] = $a;
+               if ($f == 'disabled') {
+                       $fields_host_edit3['thold_send_email'] = array(
+                               'method' => 'checkbox',
+                               'friendly_name' => 'Thold Email Host',
+                               'description' => 'Check this box to send Email for Host/Up.',
+                               'value' => '|arg1:thold_send_email|',
+                               'default' => '',
+                               'form_id' => false
+                       );
+                       $fields_host_edit3['thold_host_email'] = array(
+                               'friendly_name' => 'Additional Email address',
+                               'description' => 'Additional Email address, separated by commas for multi Emails.',
+                               'method' => 'textarea',
+                               'max_length' => 1000,
+                               'textarea_rows' => 1,
+                               'textarea_cols' => 30,
+                               'value' => '|arg1:thold_host_email|',
+                               'default' => '',
+                       );
+               }
+       }
+       $fields_host_edit = $fields_host_edit3;
+}
+
 function thold_config_settings () {
        global $tabs, $settings, $item_rows, $config;

@@ -195,6 +225,12 @@
                        'method' => 'checkbox',
                        'default' => 'on'
                        ),
+               'thold_email_prio' => array(
+                       'friendly_name' => 'Set e-mail prio to 1',
+                       'description' => 'Allows you to set e-mail priority to 1',
+                       'method' => 'checkbox',
+                       'default' => 'off'
+                       ),
                'alert_email' => array(
                        'friendly_name' => 'Dead Host Notifications Email',
                        'description' => 'This is the email address that the dead host notifications will be sent to.',
@@ -212,12 +248,12 @@
                        ),
                'thold_down_text' => array(
                        'friendly_name' => 'Down Host Message',
-                       'description' => 'This is the message that will be displayed as the message body of all UP / Down Host Messages (255 Char MAX).  HTML is allowed, but will be removed for text only emails.  There are several descriptors that may be used.<br>&#060HOSTNAME&#062  &#060DESCRIPTION&#062 &#060UPTIME&#062  &#060UPTIMETEXT&#062  &#060DOWNTIME&#062 &#060MESSAGE&#062 &#060SUBJECT&#062 &#060DOWN/UP&#062 &#060SNMP_HOSTNAME&#062 &#060SNMP_LOCATION&#062 &#060SNMP_CONTACT&#062 &#060SNMP_SYSTEM&#062 &#060LAST_FAIL&#062 &#060AVAILABILITY&#062 &#060CUR_TIME&#062 &#060AVR_TIME&#062 &#060NOTES&#062',
+                       'description' => 'This is the message that will be displayed as the message body of all UP / Down Host Messages (255 Char MAX).  HTML is allowed, but will be removed for text only emails.  There are several descriptors that may be used.<br>&#060HOSTNAME&#062  &#060DESCRIPTION&#062 &#060UPTIME&#062  &#060UPTIMETEXT&#062  &#060DOWNTIME&#062 &#060MESSAGE&#062 &#060SUBJECT&#062 &#060DOWN/UP&#062 &#060SNMP_HOSTNAME&#062 &#060SNMP_LOCATION&#062 &#060SNMP_CONTACT&#062 &#060SNMP_SYSTEM&#062 &#060LAST_FAIL&#062 &#060AVAILABILITY&#062 &#060TOT_POLL&#062 &#060FAIL_POLL&#062 &#060CUR_TIME&#062 &#060AVG_TIME&#062 &#060NOTES&#062',
                        'method' => 'textarea',
                        'class' => 'textAreaNotes',
                        'textarea_rows' => '5',
                        'textarea_cols' => '80',
-                       'default' => 'Host: <DESCRIPTION> (<HOSTNAME>)<br>Status: <DOWN/UP><br>Message: <MESSAGE><br><br>Uptime: <UPTIME> (<UPTIMETEXT>)<br>Availiability: <AVAILABILITY><br>Response: <CUR_TIME> ms<br>Down Since: <LAST_FAIL><br>NOTE: <NOTES>',
+                       'default' => 'System Error : <DESCRIPTION> (<HOSTNAME>) is <DOWN/UP><br>Reason: <MESSAGE><br><br>Average system response : <AVG_TIME> ms<br>System availability: <AVAILABILITY><br>System total pollings check: <TOT_POLL><br>System failds pollings check: <FAIL_POLL><br>Last date going DOWN : <LAST_FAIL><br>Host had been up for: <DOWNTIME><br>NOTE: <NOTES>',
                        ),
                'thold_up_subject' => array(
                        'friendly_name' => 'Recovering Host Subject',
@@ -229,12 +265,12 @@
                        ),
                'thold_up_text' => array(
                        'friendly_name' => 'Recovering Host Message',
-                       'description' => 'This is the message that will be displayed as the message body of all UP / Down Host Messages (255 Char MAX).  HTML is allowed, but will be removed for text only emails.  There are several descriptors that may be used.<br>&#060HOSTNAME&#062  &#060DESCRIPTION&#062 &#060UPTIME&#062  &#060UPTIMETEXT&#062  &#060DOWNTIME&#062 &#060MESSAGE&#062 &#060SUBJECT&#062 &#060DOWN/UP&#062 &#060SNMP_HOSTNAME&#062 &#060SNMP_LOCATION&#062 &#060SNMP_CONTACT&#062 &#060SNMP_SYSTEM&#062 &#060LAST_FAIL&#062 &#060AVAILABILITY&#062 &#060CUR_TIME&#062 &#060AVR_TIME&#062 &#060NOTES&#062',
+                       'description' => 'This is the message that will be displayed as the message body of all UP / Down Host Messages (255 Char MAX).  HTML is allowed, but will be removed for text only emails.  There are several descriptors that may be used.<br>&#060HOSTNAME&#062  &#060DESCRIPTION&#062 &#060UPTIME&#062  &#060UPTIMETEXT&#062  &#060DOWNTIME&#062 &#060MESSAGE&#062 &#060SUBJECT&#062 &#060DOWN/UP&#062 &#060SNMP_HOSTNAME&#062 &#060SNMP_LOCATION&#062 &#060SNMP_CONTACT&#062 &#060SNMP_SYSTEM&#062 &#060LAST_FAIL&#062 &#060AVAILABILITY&#062 &#060TOT_POLL&#062 &#060FAIL_POLL&#062 &#060CUR_TIME&#062 &#060AVG_TIME&#062 &#060NOTES&#062',
                        'method' => 'textarea',
                        'class' => 'textAreaNotes',
                        'textarea_rows' => '5',
                        'textarea_cols' => '80',
-                       'default' => 'Host: <DESCRIPTION> (<HOSTNAME>)<br>Status: <DOWN/UP><br>Message: <MESSAGE><br><br>Uptime: <UPTIME> (<UPTIMETEXT>)<br>Availiability: <AVAILABILITY><br>Response: <CUR_TIME> ms<br>Down Since: <LAST_FAIL><br>NOTE: <NOTES>',
+                       'default' => '<br>System <DESCRIPTION> (<HOSTNAME>) status: <DOWN/UP><br><br>Current ping response: <CUR_TIME> ms<br>Average system response : <AVG_TIME> ms<br>System availability: <AVAILABILITY><br>System total pollings check: <TOT_POLL><br>System failds pollings check: <FAIL_POLL><br>Last time see system UP: <LAST_FAIL><br>Host had been down for: <DOWNTIME><br><br>Snmp Info:<br>Name - <SNMP_HOSTNAME><br>Location - <SNMP_LOCATION><br>Uptime - <UPTIMETEXT> (<UPTIME> ms)<br>System - <SNMP_SYSTEM><br><br>NOTE: <NOTES>',
                ),
                'thold_from_email' => array(
                        'friendly_name' => 'From Email Address',
includes/polling.php

Code: Select all

--- includes/polling.php 
+++ /modif/includes/polling.php    
@@ -256,7 +256,6 @@
                                                $downtime_hours = floor(($downtime - ($downtime_days * 86400))/3600);
                                                $downtime_minutes = floor(($downtime - ($downtime_days * 86400) - ($downtime_hours * 3600))/60);
                                                $downtime_seconds = $downtime - ($downtime_days * 86400) - ($downtime_hours * 3600) - ($downtime_minutes * 60);
-                                               $msg = $msg . "<br><br>Host was down for ";
                                                if ($downtime_days > 0 ) {
                                                        $downtimemsg = $downtime_days . "d " . $downtime_hours . "h " . $downtime_minutes . "m " . $downtime_seconds . "s ";
                                                } elseif ($downtime_hours > 0 ) {
@@ -280,7 +279,7 @@

                                        $msg = read_config_option('thold_up_text');
                                        if ($msg == '') {
-                                               $msg = 'Host: <DESCRIPTION> (<HOSTNAME>)<br>Status: <DOWN/UP><br>Message: <MESSAGE><br><br>Uptime: <UPTIMETEXT><br>Availiability: <AVAILABILITY><br>Response: <CUR_TIME> ms<br>Down Since: <LAST_FAIL><br>NOTE: <NOTES>';
+                                               $msg = '<br>System <DESCRIPTION> (<HOSTNAME>) status: <DOWN/UP><br><br>Current ping response: <CUR_TIME> ms<br>Average system response : <AVG_TIME> ms<br>System availability: <AVAILABILITY><br>System total pollings check: <TOT_POLL><br>System failds pollings check: <FAIL_POLL><br>Last time see system UP: <LAST_FAIL><br>Host had been down for: <DOWNTIME><br><br>Snmp Info:<br>Name - <SNMP_HOSTNAME><br>Location - <SNMP_LOCATION><br>Uptime - <UPTIMETEXT> (<UPTIME> ms)<br>System - <SNMP_SYSTEM><br><br>NOTE: <NOTES>';
                                        }
                                        $msg = str_replace('<SUBJECT>', $subject, $msg);
                                        $msg = str_replace('<HOSTNAME>', $host['hostname'], $msg);
@@ -298,13 +297,23 @@
                                        $msg = str_replace('<SNMP_SYSTEM>', html_split_string($snmp_system), $msg);
                                        $msg = str_replace('<LAST_FAIL>', $host["status_fail_date"], $msg);
                                        $msg = str_replace('<AVAILABILITY>', round(($host["availability"]), 2) . ' %', $msg);
+                                       $msg = str_replace('<TOT_POLL>', $host["total_polls"], $msg);
+                                       $msg = str_replace('<FAIL_POLL>', $host["failed_polls"], $msg);
                                        $msg = str_replace('<CUR_TIME>', round(($host["cur_time"]), 2), $msg);
                                        $msg = str_replace('<AVG_TIME>', round(($host["avg_time"]), 2), $msg);
                                        $msg = str_replace('<NOTES>', $host["notes"], $msg);
                                        $msg = str_replace("\n", '<br>', $msg);
-                                       if ($alert_email == '') {
-                                               cacti_log('THOLD: Can not send Host Recovering email since the \'Alert e-mail\' setting is not set!', true, 'POLLER');
-                                       } else {
+                                       if ($host['thold_send_email'] == 'on' && $host['thold_host_email'] != '' ) {
+                                               $alert_email = $alert_email . ',' . $host['thold_host_email'];
+                                       }
+                                       if ($host['thold_send_email'] != 'on' && $host['thold_host_email'] != '' ) {
+                                               $alert_email = $host['thold_host_email'];
+                                       }
+                                       if ($alert_email == '') {
+                                               cacti_log('THOLD: Can not send Host Recovering email since the \'Alert e-mail\' setting is not set !', true, 'POLLER');
+                                       } elseif ($host['thold_send_email'] != 'on' && $host['thold_host_email'] == '' ) {
+                                               cacti_log('THOLD: Not send Host Recovering email, disabled per host : ' . $host['description'] . ' !', true, 'POLLER');
+                                       } else {
                                                thold_mail($alert_email, '', $subject, $msg, '');
                                        }
                                }
@@ -344,12 +353,12 @@
                        }
                        $subject = str_replace('<HOSTNAME>', $host['hostname'], $subject);
                        $subject = str_replace('<DESCRIPTION>', $host['description'], $subject);
-                       $subject = str_replace('<DOWN/UP>', 'UP', $subject);
+                       $subject = str_replace('<DOWN/UP>', 'DOWN', $subject);
                        $subject = strip_tags($subject);

                        $msg = read_config_option('thold_down_text');
                        if ($msg == '') {
-                               $msg = 'Host: <DESCRIPTION> (<HOSTNAME>)<br>Status: <DOWN/UP><br>Message: <MESSAGE><br><br>Uptime:<UPTIMETEXT><br>Availiability: <AVAILABILITY><br>Response: <CUR_TIME> ms<br>Down Since: <LAST_FAIL><br>NOTE: <NOTES>';
+                               $msg = 'System Error : <DESCRIPTION> (<HOSTNAME>) is <DOWN/UP><br>Reason: <MESSAGE><br><br>Average system response : <AVG_TIME> ms<br>System availability: <AVAILABILITY><br>System total pollings check: <TOT_POLL><br>System failds pollings check: <FAIL_POLL><br>Last date going DOWN : <LAST_FAIL><br>Host had been up for: <DOWNTIME><br>NOTE: <NOTES>';
                        }
                        $msg = str_replace('<SUBJECT>', $subject, $msg);
                        $msg = str_replace('<HOSTNAME>', $host['hostname'], $msg);
@@ -365,12 +374,22 @@
                        $msg = str_replace('<LAST_FAIL>', $host["status_fail_date"], $msg);
                        $msg = str_replace('<AVAILABILITY>', round(($host["availability"]), 2) . ' %', $msg);
                        $msg = str_replace('<CUR_TIME>', round(($host["cur_time"]), 2), $msg);
+                       $msg = str_replace('<TOT_POLL>', $host["total_polls"], $msg);
+                       $msg = str_replace('<FAIL_POLL>', $host["failed_polls"], $msg);
                        $msg = str_replace('<AVG_TIME>', round(($host["avg_time"]), 2), $msg);
                        $msg = str_replace('<NOTES>', $host["notes"], $msg);
                        $msg = str_replace("\n", '<br>', $msg);
-                       if ($alert_email == '') {
-                               cacti_log('THOLD: Can not send Host Down email since the \'Alert e-mail\' setting is not set!', true, 'POLLER');
-                       } else {
+                       if ($host['thold_send_email'] == 'on' && $host['thold_host_email'] != '' ) {
+                               $alert_email = $alert_email . ',' . $host['thold_host_email'];
+                       }
+                       if ($host['thold_send_email'] != 'on' && $host['thold_host_email'] != '' ) {
+                               $alert_email = $host['thold_host_email'];
+                       }
+                       if ($alert_email == '') {
+                               cacti_log('THOLD: Can not send Host Recovering email since the \'Alert e-mail\' setting is not set !', true, 'POLLER');
+                       } elseif ($host['thold_send_email'] != 'on' && $host['thold_host_email'] == '' ) {
+                               cacti_log('THOLD: Not send Host Recovering email, disabled per host : ' . $host['description'] . ' !', true, 'POLLER');
+                       } else {
                                thold_mail($alert_email, '', $subject, $msg, '');
                        }
                }
Attachments
new e-mail prio check
new e-mail prio check
thold setting.JPG (285.66 KiB) Viewed 17323 times
Cacti - 0.8.7h
Plugin Architecture - 3.0
Poller Type - SPINE 0.8.7g
Server Info - Linux 2.6.35.10 - Slackware 13.1
Web Server - Apache/2.2.17 (Unix) DAV/2 PHP 5.3.5
MySQL - 5.1.53 ;RRDTool - 1.4.5 ;SNMP - 5.6.1
Plugins
  • (tools - v0.3) (Thold - v0.4.6) (Ntop - v0.2) (Discovery - v1.2a) (Monitor - v1.2)
User avatar
TheWitness
Developer
Posts: 17007
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Re: Email notification update off monitor device

Post by TheWitness »

Ok, all this is committed, plus the missing database updates. I think the priority wording needs to change just a little bit though. Please test latest SVN.
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of dozens of Cacti plugins and customization's. Advocate of LAMP, MariaDB, IBM Spectrum LSF and the world of batch. Creator of IBM Spectrum RTM, author of quite a bit of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Percona Device Packages (no support)
Interesting Device Packages


For those wondering, I'm still here, but lost in the shadows. Yearning for less bugs. Who want's a Cacti 1.3/2.0? Streams anyone?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest