aboutsummaryrefslogtreecommitdiffstats
path: root/config/servicewatchdog
diff options
context:
space:
mode:
Diffstat (limited to 'config/servicewatchdog')
-rw-r--r--config/servicewatchdog/services_servicewatchdog.php44
-rw-r--r--config/servicewatchdog/servicewatchdog.inc12
-rw-r--r--config/servicewatchdog/servicewatchdog.xml18
3 files changed, 59 insertions, 15 deletions
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");
</td></tr>
<tr id="frheader">
<td width="5%" class="list">&nbsp;</td>
+<td width="5%" class="listhdrr">Notify</td>
<td width="30%" class="listhdrr"><?=gettext("Service Name");?></td>
<td width="60%" class="listhdrr"><?=gettext("Description");?></td>
<td width="5%" class="list">
@@ -164,7 +190,8 @@ foreach ($a_pwservices as $thisservice):
?>
<tr valign="top" id="fr<?=$nservices;?>">
<td class="listt"><input type="checkbox" id="frc<?=$nservices;?>" name="pwservices[]" value="<?=$i;?>" onClick="fr_bgcolor('<?=$nservices;?>')" style="margin: 0; padding: 0; width: 15px; height: 15px;" /></td>
- <td class="listlr" onclick="fr_toggle(<?=$nservices;?>)" id="frd<?=$nservices;?>" ondblclick="document.location='services_servicewatchdog_add.php?id=<?=$nservices;?>';">
+ <td class="listlr"><input type="checkbox" id="notify<?=$nservices;?>" name="notifies[]" value="<?=$i;?>" style="margin: 0; padding: 0; width: 15px; height: 15px;" <?PHP if (isset($thisservice['notify'])) echo 'checked="CHECKED"';?>/></td>
+ <td class="listr" onclick="fr_toggle(<?=$nservices;?>)" id="frd<?=$nservices;?>" ondblclick="document.location='services_servicewatchdog_add.php?id=<?=$nservices;?>';">
<?=$thisservice['name'];?>
</td>
<td class="listr" onclick="fr_toggle(<?=$nservices;?>)" id="frd<?=$nservices;?>" ondblclick="document.location='services_servicewatchdog_add.php?id=<?=$nservices;?>';">
@@ -180,7 +207,7 @@ foreach ($a_pwservices as $thisservice):
</td></tr>
<?php $i++; $nservices++; endforeach; ?>
<tr>
- <td class="list" colspan="3"></td>
+ <td class="list" colspan="4"></td>
<td class="list" valign="middle" nowrap>
<table border="0" cellspacing="0" cellpadding="1" summary="add">
<tr>
@@ -199,7 +226,14 @@ foreach ($a_pwservices as $thisservice):
</table>
</td>
</tr>
- <tr><td></td><td colspan="3">
+ <tr><td></td><td colspan="4">
+ <?php echo gettext("Check Notify next to services to perform an e-mail notification when the service is restarted. Configure e-mail notifications to receive the alerts."); ?>
+ <br/>
+ <input name="Update" type="submit" class="formbtn" value="<?=gettext("Update Notification Settings"); ?>" />
+ <br/>
+ <br/>
+ </td><td></td></tr>
+ <tr><td></td><td colspan="4">
<?php echo gettext("Click to select a service and use the arrows to re-order them in the list. Higher services are checked first."); ?>
</td><td></td></tr>
</table>
diff --git a/config/servicewatchdog/servicewatchdog.inc b/config/servicewatchdog/servicewatchdog.inc
index 1bdb1ce9..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. */
@@ -48,14 +49,14 @@ function servicewatchdog_is_service_watched($svc) {
return false;
}
-function servicewatchdog_cron_job() {
+function servicewatchdog_cron_job($force_remove) {
global $config;
if (!is_array($config['installedpackages']['servicewatchdog']['item'])) {
$config['installedpackages']['servicewatchdog']['item'] = array();
}
$a_pwservices = &$config['installedpackages']['servicewatchdog']['item'];
- if (count($a_pwservices) > 0) {
+ if (($force_remove == false) && (count($a_pwservices) > 0)) {
// Add the cron job if it doesn't exist.
install_cron_job("/usr/local/pkg/servicewatchdog_cron.php", true, "*/1");
} else {
@@ -74,10 +75,13 @@ 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);
}
}
}
-?> \ No newline at end of file
+?>
diff --git a/config/servicewatchdog/servicewatchdog.xml b/config/servicewatchdog/servicewatchdog.xml
index 5e1ce309..685ba997 100644
--- a/config/servicewatchdog/servicewatchdog.xml
+++ b/config/servicewatchdog/servicewatchdog.xml
@@ -40,7 +40,7 @@
<requirements>None</requirements>
<faq>Monitors for stopped services and restarts them.</faq>
<name>Service Watchdog</name>
- <version>1.4</version>
+ <version>1.6</version>
<title>Services: Service Watchdog</title>
<include_file>/usr/local/pkg/servicewatchdog.inc</include_file>
<menu>
@@ -52,21 +52,27 @@
<additional_files_needed>
<prefix>/usr/local/www/</prefix>
<chmod>644</chmod>
- <item>http://www.pfsense.com/packages/config/servicewatchdog/services_servicewatchdog.php</item>
+ <item>https://packages.pfsense.org/packages/config/servicewatchdog/services_servicewatchdog.php</item>
</additional_files_needed>
<additional_files_needed>
<prefix>/usr/local/www/</prefix>
<chmod>644</chmod>
- <item>http://www.pfsense.com/packages/config/servicewatchdog/services_servicewatchdog_add.php</item>
+ <item>https://packages.pfsense.org/packages/config/servicewatchdog/services_servicewatchdog_add.php</item>
</additional_files_needed>
<additional_files_needed>
<prefix>/usr/local/pkg/</prefix>
<chmod>755</chmod>
- <item>http://www.pfsense.com/packages/config/servicewatchdog/servicewatchdog_cron.php</item>
+ <item>https://packages.pfsense.org/packages/config/servicewatchdog/servicewatchdog_cron.php</item>
</additional_files_needed>
<additional_files_needed>
<prefix>/usr/local/pkg/</prefix>
<chmod>644</chmod>
- <item>http://www.pfsense.com/packages/config/servicewatchdog/servicewatchdog.inc</item>
+ <item>https://packages.pfsense.org/packages/config/servicewatchdog/servicewatchdog.inc</item>
</additional_files_needed>
-</packagegui> \ No newline at end of file
+ <custom_php_install_command>
+ servicewatchdog_cron_job();
+ </custom_php_install_command>
+ <custom_php_deinstall_command>
+ servicewatchdog_cron_job(true);
+ </custom_php_deinstall_command>
+</packagegui>