function boost_graph_set_file(&$output, $local_graph_id, $rra_id) { global $config, $boost_sock, $graph_data_array; /* get access to the SNMP Cache of BOOST*/ $mc = new MibCache('CACTI-BOOST-MIB'); /* suppress warnings */ if (defined('E_DEPRECATED')) { error_reporting(E_ALL ^ E_DEPRECATED); } else { error_reporting(E_ALL); } /* install the boost error handler */ set_error_handler('boost_error_handler'); if (isset($_SESSION['sess_current_timespan'])) { $timespan = $_SESSION['sess_current_timespan']; } else { $timespan = 0; } /* check the graph cache and use it if it is valid, otherwise turn over to * cacti's graphing fucntions. */ if (read_config_option('boost_png_cache_enable') && boost_determine_caching_state()) { $cache_directory = read_config_option('boost_png_cache_directory'); if (strlen($cache_directory)) { if (is_dir($cache_directory)) { if ($rra_id > 0) { $cache_file = $cache_directory . '/lgi_' . $local_graph_id . '_rrai_' . $rra_id; } else { $cache_file = $cache_directory . '/lgi_' . $local_graph_id . '_rrai_' . $rra_id . '_tsi_' . $timespan; } if (isset($graph_data_array['graph_height'])) { $cache_file .= '_height_' . $graph_data_array['graph_height']; } if (isset($graph_data_array['graph_width'])) { $cache_file .= '_width_' . $graph_data_array['graph_width']; } if (isset($graph_data_array['graph_nolegend'])) { $cache_file .= '_thumb.png'; } else { $cache_file .= '.png'; } if (is_writable($cache_directory)) { /* if the cache file was created in a prior step, save it */ if (strlen($output) > 10) { if ($fileptr = fopen($cache_file, 'w')) { fwrite($fileptr, $output, strlen($output)); fclose($fileptr); chmod($cache_file, 0666); /* count the number of images that had to be cached */ $mc->object('boostStatsTotalsImagesCacheWrites')->count(); $mc->object('boostStatsLastUpdate')->set(time()); } } } else { cacti_log('ERROR: Boost Cache Directory is not writable! Can not cache images', false, 'BOOST'); } } else { cacti_log('ERROR: Boost Cache Directory does not exist! Can not cache images', false, 'BOOST'); } } else { cacti_log('ERROR: Boost Cache Directory variable is not set! Can not cache images', false, 'BOOST'); } } /* restore original error handler */ restore_error_handler(); }
function snmpagent_poller_bottom() { global $config; if (api_plugin_is_enabled('maint')) { include_once $config["base_path"] . '/plugins/maint/functions.php'; } $device_in_maintenance = false; $mc = new MibCache(); /* START: update total device stats table */ /***** deprecated ******/ $devicestatus_indices = array(0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4); $current_states = db_fetch_assoc("SELECT status, COUNT(*) as cnt FROM `host` GROUP BY status"); if ($current_states && sizeof($current_states) > 0) { foreach ($current_states as $current_state) { $index = $devicestatus_indices[$current_state["status"]]; $values = array("cactiStatsTotalsDeviceStatusIndex" => $current_state["status"], "cactiStatsTotalsDeviceStatusCounter" => $current_state["cnt"]); $mc->table('cactiStatsTotalsDeviceStatusTable')->row($index)->replace($values); unset($devicestatus_indices[$current_state["status"]]); } } if (sizeof($devicestatus_indices) > 0) { foreach ($devicestatus_indices as $status => $index) { $values = array("cactiStatsTotalsDeviceStatusIndex" => $status, "cactiStatsTotalsDeviceStatusCounter" => 0); $mc->table('cactiStatsTotalsDeviceStatusTable')->row($index)->replace($values); } } /************************/ $mc->object('cactiStatsTotalsDeviceStatusUnknown')->set(snmpagent_read('cactiStatsTotalsDeviceStatusUnknown')); $mc->object('cactiStatsTotalsDeviceStatusDown')->set(snmpagent_read('cactiStatsTotalsDeviceStatusDown')); $mc->object('cactiStatsTotalsDeviceStatusRecovering')->set(snmpagent_read('cactiStatsTotalsDeviceStatusRecovering')); $mc->object('cactiStatsTotalsDeviceStatusUp')->set(snmpagent_read('cactiStatsTotalsDeviceStatusUp')); $mc->object('cactiStatsTotalsDeviceStatusDisabled')->set(snmpagent_read('cactiStatsTotalsDeviceStatusDisabled')); /* END: update total device stats table */ /* update state and statistics of all devices */ $mc_dstatus = array(); $mc_devices = $mc->table('cactiApplDeviceTable')->select(array('cactiApplDeviceIndex', 'cactiApplDeviceStatus')); if ($mc_devices && sizeof($mc_devices) > 0) { foreach ($mc_devices as $mc_device) { $mc_dstatus[$mc_device['cactiApplDeviceIndex']] = $mc_device['cactiApplDeviceStatus']; } } $mc_dfailed = array(); $mc_device_stats = $mc->table('cactiStatsDeviceTable')->select(array('cactiStatsDeviceIndex', 'cactiStatsDeviceFailedPolls')); if ($mc_device_stats && sizeof($mc_device_stats) > 0) { foreach ($mc_device_stats as $mc_device_stat) { $mc_dfailed[$mc_device_stat['cactiStatsDeviceIndex']] = $mc_device_stat['cactiStatsDeviceFailedPolls']; } } $devices = db_fetch_assoc("SELECT id, description, hostname, status, disabled, status_event_count, status_fail_date, status_rec_date, status_last_error, min_time, max_time, cur_time, avg_time, total_polls, failed_polls, availability FROM host ORDER BY id ASC"); if ($devices && sizeof($devices) > 0) { foreach ($devices as $device) { if (function_exists('plugin_maint_check_cacti_host')) { $device_in_maintenance = plugin_maint_check_cacti_host($index); } if (!$device_in_maintenance) { $varbinds = array('cactiApplDeviceIndex' => $device["id"], 'cactiApplDeviceDescription' => $device["description"], 'cactiApplDeviceHostname' => $device["hostname"], 'cactiApplDeviceLastError' => $device["status_last_error"]); if ($device["failed_polls"] > $mc_dfailed[$device["id"]]) { snmpagent_notification('cactiNotifyDeviceFailedPoll', 'CACTI-MIB', $varbinds); } if ($mc_dstatus[$device["id"]] == HOST_UP && $device["status"] == HOST_DOWN) { snmpagent_notification('cactiNotifyDeviceDown', 'CACTI-MIB', $varbinds, EVENT_SEVERITY_HIGH); } elseif ($mc_dstatus[$device["id"]] == HOST_DOWN && $device["status"] == HOST_RECOVERING) { snmpagent_notification('cactiNotifyDeviceRecovering', 'CACTI-MIB', $varbinds); } } $values = array("cactiApplDeviceStatus" => $device["disabled"] == 'on' ? 4 : $device["status"], "cactiApplDeviceEventCount" => $device["status_event_count"], "cactiApplDeviceFailDate" => $device["status_fail_date"], "cactiApplDeviceRecoveryDate" => $device["status_rec_date"], "cactiApplDeviceLastError" => $device["status_last_error"]); $mc->table('cactiApplDeviceTable')->row($device["id"])->update($values); $values = array("cactiStatsDeviceMinTime" => $device["min_time"], "cactiStatsDeviceMaxTime" => $device["max_time"], "cactiStatsDeviceCurTime" => $device["cur_time"], "cactiStatsDeviceAvgTime" => $device["avg_time"], "cactiStatsDeviceTotalPolls" => $device["total_polls"], "cactiStatsDeviceFailedPolls" => $device["failed_polls"], "cactiStatsDeviceAvailability" => $device["availability"]); $mc->table('cactiStatsDeviceTable')->row($device["id"])->update($values); } } /* get a list of all plugins available on that system */ $pluginslist = snmpagent_get_pluginslist(); /* truncate plugin mib table */ $mc->table('cactiApplPluginTable')->truncate(); /* refill plugin mib table */ if ($pluginslist && sizeof($pluginslist) > 0) { $i = 1; foreach ($pluginslist as $plugin) { $values = array("cactiApplPluginIndex" => $i, "cactiApplPluginType" => 2, "cactiApplPluginName" => $plugin["directory"], "cactiApplPluginStatus" => $plugin["status"], "cactiApplPluginVersion" => $plugin["version"]); $mc->table('cactiApplPluginTable')->row($i)->insert($values); $i++; } } $mc->object('cactiApplLastUpdate')->set(time()); $recache_stats = db_fetch_cell("SELECT value FROM settings WHERE name = 'stats_recache'"); if ($recache_stats) { list($time, $hosts) = explode(" ", $recache_stats); $time = str_replace("RecacheTime:", "", $time); $hosts = str_replace("HostsRecached:", "", $hosts); } $mc->object('cactiStatsRecacheTime')->set($time); $mc->object('cactiStatsRecachedHosts')->set($hosts); $mc->object('cactiStatsLastUpdate')->set(time()); /* clean up the notification log */ $snmp_notification_managers = db_fetch_assoc("SELECT id, max_log_size FROM snmpagent_managers"); if ($snmp_notification_managers && sizeof($snmp_notification_managers) > 0) { foreach ($snmp_notification_managers as $snmp_notification_manager) { db_execute("DELETE FROM snmpagent_notifications_log WHERE manager_id = " . $snmp_notification_manager["id"] . " AND `time` <= " . (time() - 86400 * $snmp_notification_manager["max_log_size"])); } } }