From 8effac5182368b998e3866ab1eae58828188ca9e Mon Sep 17 00:00:00 2001 From: jim-p Date: Fri, 25 Apr 2014 14:27:50 -0400 Subject: Add option to send e-mail notifications when Service Watchdog restarts a service; Bump version. --- .../servicewatchdog/services_servicewatchdog.php | 44 +++++++++++++++++++--- config/servicewatchdog/servicewatchdog.inc | 6 ++- config/servicewatchdog/servicewatchdog.xml | 2 +- 3 files changed, 45 insertions(+), 7 deletions(-) (limited to 'config/servicewatchdog') diff --git a/config/servicewatchdog/services_servicewatchdog.php b/config/servicewatchdog/services_servicewatchdog.php index 920fd1bb..bd4d4442 100644 --- a/config/servicewatchdog/services_servicewatchdog.php +++ b/config/servicewatchdog/services_servicewatchdog.php @@ -56,8 +56,33 @@ if ($_GET['act'] == "del") { servicewatchdog_cron_job(); write_config(); header("Location: services_servicewatchdog.php"); - exit; + return; + } +} + +if (isset($_POST['Update'])) { + /* update selected services */ + if (is_array($_POST['notifies']) && count($_POST['notifies'])) { + /* Check each service and set the notify flag only for those chosen, remove those that are unset. */ + foreach ($a_pwservices as $idx => $thisservice) { + if (!is_array($thisservice)) + continue; + if (in_array($idx, $_POST['notifies'])) { + $a_pwservices[$idx]['notify'] = true; + } else { + if (isset($a_pwservices[$idx]['notify'])) + unset($a_pwservices[$idx]['notify']); + } + } + } else { /* No notifies selected, remove them all. */ + foreach ($a_pwservices as $idx => $thisservice) { + unset($a_pwservices[$idx]['notify']); + } } + servicewatchdog_cron_job(); + write_config(); + header("Location: services_servicewatchdog.php"); + return; } if (isset($_POST['del_x'])) { @@ -69,7 +94,7 @@ if (isset($_POST['del_x'])) { servicewatchdog_cron_job(); write_config(); header("Location: services_servicewatchdog.php"); - exit; + return; } } else { /* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */ @@ -141,6 +166,7 @@ include("head.inc");   +Notify @@ -164,7 +190,8 @@ foreach ($a_pwservices as $thisservice): ?> - + /> + @@ -180,7 +207,7 @@ foreach ($a_pwservices as $thisservice): - + @@ -199,7 +226,14 @@ foreach ($a_pwservices as $thisservice):
- + + +
+ " /> +
+
+ + diff --git a/config/servicewatchdog/servicewatchdog.inc b/config/servicewatchdog/servicewatchdog.inc index 696e570e..5b638836 100644 --- a/config/servicewatchdog/servicewatchdog.inc +++ b/config/servicewatchdog/servicewatchdog.inc @@ -3,6 +3,7 @@ require_once("config.inc"); require_once("services.inc"); require_once("service-utils.inc"); require_once("util.inc"); +require_once("notices.inc"); function servicewatchdog_service_matches($svc1, $svc2) { /* If the arrays are equal, it must be the same service. */ @@ -74,7 +75,10 @@ function servicewatchdog_check_services() { foreach ($a_pwservices as $svc) { if (!get_service_status($svc)) { $descr = strlen($svc['description']) > 50 ? substr($svc['description'], 0, 50) . "..." : $svc['description']; - log_error("Service Watchdog detected service {$svc['name']} stopped. Restarting {$svc['name']} ({$descr})"); + $error_message = "Service Watchdog detected service {$svc['name']} stopped. Restarting {$svc['name']} ({$descr})"; + log_error($error_message); + if (isset($svc['notify'])) + notify_via_smtp($error_message); service_control_start($svc['name'], $svc); } } diff --git a/config/servicewatchdog/servicewatchdog.xml b/config/servicewatchdog/servicewatchdog.xml index e66f878d..685ba997 100644 --- a/config/servicewatchdog/servicewatchdog.xml +++ b/config/servicewatchdog/servicewatchdog.xml @@ -40,7 +40,7 @@ None Monitors for stopped services and restarts them. Service Watchdog - 1.5 + 1.6 Services: Service Watchdog /usr/local/pkg/servicewatchdog.inc -- cgit v1.2.3