예제 #1
0
파일: snmpagent.php 프로젝트: MrWnn/cacti
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"]));
        }
    }
}
예제 #2
0
function thold_snmptrap($varbinds)
{
    if (function_exists('snmpagent_notification')) {
        snmpagent_notification('tholdNotify', 'CACTI-THOLD-MIB', $varbinds);
    } else {
        cacti_log("ERROR: THOLD was unable to generate SNMP notifications. Cacti SNMPAgent plugin is current missing or inactive.");
    }
}