almost feature complete. if testing please re-install

there are table changes in this commit.  please re-install
This commit is contained in:
cigamit committed 2016-07-04 17:07:11 -05:00
1 parent ada5e4f36b
commit 056cd171f9
17 files changed
+770 -568

No files matched your search

+4 -1
View File
@@ -15,6 +15,10 @@
This plugin allows you to view at a glance all your Cacti hosts, and will alert you audibly when something is down.
In addition, you may receive notification if any critical host becomes unreachable.
Some audio clips courtesy of SoundBible.com and licensed under Creative Common and other Free to use Licenses.
If you create an MP3 file called 'First Order Chorus.mp3' and place it in the sound folder, you may get a surprise
if you choose to use it.
----[ Features
Audible alert
@@ -31,7 +35,6 @@
If you figure out this problem, let me know!!!
----[ Future Changes
Got any ideas or complaints, please e-mail me!
+604 -508
View File
File diff suppressed because it is too large. Load diff
+101 -44
View File
@@ -76,13 +76,16 @@ foreach ($parms as $parameter) {
monitor_debug('Monitor Starting Checks');
list($reboots, $recent_down) = monitor_uptime_checker();
$warning_criticality = read_config_option('monitor_warn_criticality');
$alert_criticality = read_config_option('monitor_alert_criticality');
$lists = array();
$global_list = array();
$notify_list = array();
$last_time = date("Y-m-d H:i:s", time() - read_config_option('monitor_resend_frequency') * 60);
$lists = array();
$notifications = 0;
$global_list = array();
$notify_list = array();
$last_time = date("Y-m-d H:i:s", time() - read_config_option('monitor_resend_frequency') * 60);
if ($warning_criticality > 0 || $alert_criticality > 0) {
monitor_debug('Monitor Notification Enabled for Devices');
@@ -113,7 +116,10 @@ if ($warning_criticality > 0 || $alert_criticality > 0) {
if (sizeof($notification_emails)) {
foreach($notification_emails as $email => $lists) {
monitor_debug('Processing the email address: ' . $email);
process_email($email, $lists, $global_list, $notify_list);
$notifications++;
}
}
}
@@ -121,11 +127,53 @@ if ($warning_criticality > 0 || $alert_criticality > 0) {
monitor_debug('Both Warning and Alert Notification are Disabled.');
}
list($purge_n, $purge_r) = purge_event_records();
$poller_end = microtime(true);
cacti_log('MONITOR STATS: Time:' . round($poller_end-$poller_start, 2), false, 'SYSTEM');
cacti_log('MONITOR STATS: Time:' . round($poller_end-$poller_start, 2) . ' Reboots:' . $reboots . ' DownDevices:' . $recent_down . ' Notifications:' . $notifications . ' Purges:' . ($purge_n + $purge_r), false, 'SYSTEM');
exit;
function monitor_uptime_checker() {
monitor_debug('Checking for Uptime of Devices');
$start = date('Y-m-d H:i:s');
// Get the rebooted devices
$rebooted_hosts = db_fetch_assoc("SELECT h.id, h.snmp_sysUpTimeInstance, mu.uptime
FROM host AS h
LEFT JOIN plugin_monitor_uptime AS mu
ON h.id=mu.host_id
WHERE h.snmp_version>0 AND status IN (2,3)
AND (mu.uptime IS NULL OR mu.uptime > h.snmp_sysUpTimeInstance)");
if (sizeof($rebooted_hosts)) {
foreach($rebooted_hosts as $host) {
db_execute_prepared('INSERT INTO plugin_monitor_reboot_history (host_id, reboot_time) VALUES (?, ?)',
array($host['id'], date('Y-m-d H:i:s', time()-$host['snmp_sysUpTimeInstance'])));
}
}
// Freshen the uptimes
db_execute("REPLACE INTO plugin_monitor_uptime (host_id, uptime)
SELECT id, snmp_sysUpTimeInstance FROM host WHERE snmp_version>0 AND status IN(2,3)");
// Log Recently Down
db_execute("INSERT IGNORE INTO plugin_monitor_notify_history
(host_id, notify_type, notification_time, notes)
SELECT h.id, '3' AS notify_type, status_fail_date AS notification_time, status_last_error AS notes
FROM host AS h
WHERE status=1 AND status_event_count=1");
$recent = db_affected_rows();
return array(sizeof($rebooted_hosts), $recent);
}
function process_email($email, $lists, $global_list, $notify_list) {
define('BR', "\n");
monitor_debug('Into Processing');
$alert_hosts = array();
$warn_hosts = array();
@@ -181,60 +229,61 @@ function process_email($email, $lists, $global_list, $notify_list) {
$freq = read_config_option('monitor_resend_frequency');
$subject = __('Cacti Monitor Plugin Ping Threshold Notification');
$body = '<h1>' . __('Cacti Monitor Plugin Ping Threshold Notication') . '</h1>';
$body = '<h1>' . __('Cacti Monitor Plugin Ping Threshold Notication') . '</h1>' . BR;
$body .= '<p>' . __('The following report will identify Devices that have eclipsed their ping
latency thresholds. You are receiving this report due to that you are subscribed for notification
to a Device associated with the Cacti system located at the following URL below.') . '</p>';
latency thresholds. You are receiving this report since you are subscribed to a Device
associated with the Cacti system located at the following URL below.') . '</p>' . BR;
$body .= '<h2>' . read_config_option('base_url') . '</h2>';
$body .= '<h2><a href="' . read_config_option('base_url') . '">Cacti Monitoring Site</a></h2>' . BR;
if ($freq > 0) {
$body .= '<p>' . __('You will receive notifications every %d minutes if the Device is above its threshold.', $freq) . '</p>';
$body .= '<p>' . __('You will receive notifications every %d minutes if the Device is above its threshold.', $freq) . '</p>' . BR;
}else{
$body .= '<p>' . __('You will receive notifications every time the Device is above its threshold.') . '</p>';
$body .= '<p>' . __('You will receive notifications every time the Device is above its threshold.') . '</p>' . BR;
}
if (sizeof($alert_hosts)) {
$body .= '<p>' . __('The following Devices have breached their Alert Notification Threshold.') . '</p>';
$body .= '<table style="width:100%;border:1px solid black;padding:4px;margin:2px;text-align:left;"><tr>';
$body .= '<th style="text-align:left;">Hostname</th><th style="text-align:left;">Criticality</th><th style="text-align:right;">Alert Ping</th><th style="text-align:right;">Cur Ping</th>';
$body .= '</tr>';
$body .= '<p>' . __('The following Devices have breached their Alert Notification Threshold.') . '</p>' . BR;
$body .= '<table class="report_table">' . BR;
$body .= '<tr class="header_row">' . BR;
$body .= '<th class="left">Hostname</th><th class="left">Criticality</th><th class="right">Alert Ping</th><th class="right">Current Ping</th>' . BR;
$body .= '</tr>' . BR;
$hosts = db_fetch_assoc('SELECT * FROM host WHERE id IN(' . implode(',', $alert_hosts) . ')');
if (sizeof($hosts)) {
foreach($hosts as $host) {
$body .= '<tr>';
$body .= '<td style="text-align:left;">' . $host['description'] . '</td>';
$body .= '<td style="text-align:left;">' . $criticalities[$host['monitor_criticality']] . '</td>';
$body .= '<td style="text-align:right;">' . round($host['monitor_alert'],2) . ' ms</td>';
$body .= '<td style="text-align:right;">' . round($host['cur_time'],2) . ' ms</td>';
$body .= '</tr>';
$body .= '<tr>' . BR;
$body .= '<td class="left">' . $host['description'] . '</td>' . BR;
$body .= '<td class="left">' . $criticalities[$host['monitor_criticality']] . '</td>' . BR;
$body .= '<td class="right">' . round($host['monitor_alert'],2) . ' ms</td>' . BR;
$body .= '<td class="right">' . round($host['cur_time'],2) . ' ms</td>' . BR;
$body .= '</tr>' . BR;
}
}
$body .= '</table>';
$body .= '</table>' . BR;
}
if (sizeof($warn_hosts)) {
$body .= '<p>' . __('The following Devices have breached their Warning Notification Threshold.') . '</p><br>';
$body .= '<p>' . __('The following Devices have breached their Warning Notification Threshold.') . '</p>' . BR;
$body .= '<table style="width:100%;border:1px solid black;padding:4px;margin:2px;text-align:left;">';
$body .= '<tr>';
$body .= '<th>Hostname</th><th>Criticality</th><th>Alert Ping</th><th>Cur Ping</th>';
$body .= '</tr>';
$body .= '<table class="report_table">' . BR;
$body .= '<tr class="header_row">' . BR;
$body .= '<th class="left">Hostname</th><th class="left">Criticality</th><th class="right">Alert Ping</th><th class="right">Current Ping</th>' . BR;
$body .= '</tr>' . BR;
$hosts = db_fetch_assoc('SELECT * FROM host WHERE id IN(' . implode(',', $warn_hosts) . ')');
if (sizeof($hosts)) {
foreach($hosts as $host) {
$body .= '<tr>';
$body .= '<td style="text-align:left;">' . $host['description'] . '</td>';
$body .= '<td style="text-align:left;">' . $criticalities[$host['monitor_criticality']] . '</td>';
$body .= '<td style="text-align:right;">' . round($host['monitor_warn'],2) . ' ms</td>';
$body .= '<td style="text-align:right;">' . round($host['cur_time'],2) . ' ms</td>';
$body .= '</tr>';
$body .= '<tr>' . BR;
$body .= '<td class="left">' . $host['description'] . '</td>' . BR;
$body .= '<td class="left">' . $criticalities[$host['monitor_criticality']] . '</td>' . BR;
$body .= '<td class="right">' . round($host['monitor_warn'],2) . ' ms</td>' . BR;
$body .= '<td class="right">' . round($host['cur_time'],2) . ' ms</td>' . BR;
$body .= '</tr>' . BR;
}
}
$body .= '</table>';
$body .= '</table>' . BR;
}
$output = '';
@@ -281,7 +330,7 @@ function process_email($email, $lists, $global_list, $notify_list) {
'',
'',
$subject,
$body,
$output,
'Cacti Monitor Plugin requires an html based e-mail client',
'',
$headers
@@ -305,16 +354,18 @@ function log_messages($type, $alert_hosts) {
static $processed = array();
if ($type == 'warn') {
$type = '0';
$type = '0';
$column = 'monitor_warn';
}elseif ($type == 'alert') {
$type = '1';
$column = 'monitor_alert';
}
foreach($alert_hosts as $id) {
if (!isset($processed[$id])) {
db_execute_prepared('INSERT INTO plugin_monitor_notify_history
(host_id, notify_type, ping_time, notification_time)
SELECT id, ?, cur_time, ? FROM host WHERE id = ?', array($type, $start_date, $id));
(host_id, notify_type, ping_time, ping_threshold, notification_time)
SELECT id, ?, cur_time, ?, ? FROM host WHERE id = ?', array($type, $column, $start_date, $id));
}
$processed[$id] = true;
@@ -434,15 +485,21 @@ function get_emails_and_lists($lists) {
function purge_event_records() {
// Purge old records
db_execute('DELETE FROM plugin_monitor_notify_history
WHERE notification_time<FROM_UNIXTIME(UNIX_TIMESTAMP()-(? * 86400)',
array(read_config_option('monitor_log_storage')));
$days = read_config_option('monitor_log_storage');
if (empty($days)) {
$days = 120;
}
db_execute_prepared('DELETE FROM plugin_monitor_notify_history
WHERE notification_time<FROM_UNIXTIME(UNIX_TIMESTAMP()-(? * 86400))', array($days));
$purge_n = db_affected_rows();
db_execute('DELETE FROM plugin_monitor_reboot_history
WHERE notification_time<FROM_UNIXTIME(UNIX_TIMESTAMP()-(? * 86400)',
array(read_config_option('monitor_log_storage')));
db_execute_prepared('DELETE FROM plugin_monitor_reboot_history
WHERE log_time<FROM_UNIXTIME(UNIX_TIMESTAMP()-(? * 86400))', array($days));
$purge_r = db_affected_rows();
return(array($purge_n, $purge_r));
}
function monitor_debug($message) {
+61 -15
View File
@@ -34,18 +34,23 @@ function plugin_monitor_install () {
api_plugin_register_hook('monitor', 'device_action_execute', 'monitor_device_action_execute', 'setup.php');
api_plugin_register_hook('monitor', 'device_action_prepare', 'monitor_device_action_prepare', 'setup.php');
api_plugin_register_hook('monitor', 'poller_bottom', 'monitor_poller_bottom', 'setup.php');
api_plugin_register_hook('monitor', 'device_remove', 'monitor_device_remove', 'setup.php');
api_plugin_register_realm('monitor', 'monitor.php', 'View Monitoring Dashboard', 1);
api_plugin_register_realm('monitor', 'monitor.php', 'View Monitoring', 1);
monitor_setup_table();
}
function plugin_monitor_uninstall () {
db_remove_column('monitor');
db_remove_column('monitor_text');
db_remove_column('monitor_criticality');
db_remove_column('monitor_warn');
db_remove_column('monitor_alert');
// Do any extra Uninstall stuff here
db_remove_column('host', 'monitor');
db_remove_column('host', 'monitor_text');
db_remove_column('host', 'monitor_criticality');
db_remove_column('host', 'monitor_warn');
db_remove_column('host', 'monitor_alert');
db_execute('DROP TABLE IF EXISTS plugin_monitor_notify_history');
db_execute('DROP TABLE IF EXISTS plugin_monitor_reboot_history');
db_execute('DROP TABLE IF EXISTS plugin_monitor_uptime');
}
function plugin_monitor_check_config () {
@@ -161,6 +166,14 @@ function monitor_device_action_execute($action) {
return $action;
}
function monitor_device_remove($devices) {
db_execute('DELETE FROM plugin_monitor_notify_history WHERE host_id IN(' . implode(',', $devices) . ')');
db_execute('DELETE FROM plugin_monitor_reboot_history WHERE host_id IN(' . implode(',', $devices) . ')');
db_execute('DELETE FROM plugin_monitor_uptime WHERE host_id IN(' . implode(',', $devices) . ')');
return $devices;
}
function monitor_device_action_prepare($save) {
global $host_list, $fields_host_edit;
@@ -249,7 +262,7 @@ function monitor_scan_dir() {
}
function monitor_config_settings() {
global $tabs, $settings, $criticalities, $page_refresh_interval, $config;
global $tabs, $settings, $criticalities, $page_refresh_interval, $config, $settings_user, $tabs_graphs;
include_once($config['base_path'] . '/lib/reports.php');
@@ -273,11 +286,30 @@ function monitor_config_settings() {
'365' => __('%d Year', 1)
);
$tabs_graphs += array('monitor' => 'Monitor Settings');
$settings_user += array(
'monitor' => array(
'monitor_sound' => array(
'friendly_name' => __('Alarm Sound'),
'description' => __('This is the sound file that will be played when a Device goes down.'),
'method' => 'drop_array',
'array' => monitor_scan_dir(),
'default' => 'attn-noc.wav',
),
'monitor_legend' => array(
'friendly_name' => __('Show Icon Legend'),
'description' => __('Check this to show an icon legend on the Monitor display'),
'method' => 'checkbox',
)
)
);
if (isset($_SERVER['PHP_SELF']) && basename($_SERVER['PHP_SELF']) != 'settings.php') {
return;
}
$tabs['misc'] = 'Misc';
$tabs['monitor'] = 'Monitor';
$temp = array(
'monitor_header' => array(
@@ -371,10 +403,10 @@ function monitor_config_settings() {
)
);
if (isset($settings['misc'])) {
$settings['misc'] = array_merge($settings['misc'], $temp);
if (isset($settings['monitor'])) {
$settings['monitor'] = array_merge($settings['monitor'], $temp);
} else {
$settings['misc']=$temp;
$settings['monitor'] = $temp;
}
}
@@ -539,14 +571,14 @@ function monitor_api_device_save ($save) {
if (!isempty_request_var('monitor_alert_baseline') && !empty($save['id'])) {
$cur_time = db_fetch_cell_prepared('SELECT cur_time FROM host WHERE id = ?', array($save['id']));
if ($cur_time > 0) {
$save['monitor_alert'] = $cur_time * get_nfilter_request_var('monitor_alert_baseline');
$save['monitor_alert'] = round($cur_time * get_nfilter_request_var('monitor_alert_baseline'),0);
}
}
if (!isempty_request_var('monitor_warn_baseline') && !empty($save['id'])) {
$cur_time = db_fetch_cell_prepared('SELECT cur_time FROM host WHERE id = ?', array($save['id']));
if ($cur_time > 0) {
$save['monitor_warn'] = $cur_time * get_nfilter_request_var('monitor_alert_baseline');
$save['monitor_warn'] = round($cur_time * get_nfilter_request_var('monitor_alert_baseline'),0);
}
}
@@ -566,7 +598,9 @@ function monitor_setup_table() {
host_id int(10) unsigned DEFAULT NULL,
notify_type tinyint(3) unsigned DEFAULT NULL,
ping_time double DEFAULT NULL,
ping_threshold int(10) unsigned DEFAULT NULL,
notification_time timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
notes varchar(255) DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE KEY unique_key (host_id,notify_type,notification_time))
ENGINE=InnoDB
@@ -578,13 +612,25 @@ function monitor_setup_table() {
id int(10) unsigned NOT NULL AUTO_INCREMENT,
host_id int(10) unsigned DEFAULT NULL,
reboot_time timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
log_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
PRIMARY KEY (id),
KEY host_id (host_id),
KEY reboot_time (reboot_time))
KEY log_time (log_time),
KEY reboot_time (reboot_time))
ENGINE=InnoDB
COMMENT='Keeps Track of Device Reboot Times'");
}
if (!db_table_exists('plugin_monitor_uptime')) {
db_execute("CREATE TABLE IF NOT EXISTS plugin_monitor_uptime (
host_id int(10) unsigned DEFAULT '0',
uptime int(10) unsigned DEFAULT '0',
PRIMARY KEY (host_id),
KEY uptime (uptime))
ENGINE=InnoDB
COMMENT='Keeps Track of the Devices last uptime to track agent restarts and reboots'");
}
api_plugin_db_add_column ('monitor', 'host', array('name' => 'monitor', 'type' => 'char(3)', 'NULL' => false, 'default' => 'on', 'after' => 'disabled'));
api_plugin_db_add_column ('monitor', 'host', array('name' => 'monitor_text', 'type' => 'text', 'NULL' => false, 'after' => 'monitor'));
api_plugin_db_add_column ('monitor', 'host', array('name' => 'monitor_criticality', 'type' => 'tinyint', 'unsigned' => true, 'NULL' => false, 'default' => '0', 'after' => 'monitor_text'));
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.