Exemple #1
0
function snmpagent_cache_init()
{
    /* fill up the cache with a minimum of data data and ignore all values that
     *  will be updated automatically at the bottom of the next poller run
     */
    $mc = new MibCache();
    /* update global settings */
    snmpagent_global_settings_update();
    /* add pollers of a distributed system (future) */
    $pollers = db_fetch_assoc("SELECT id FROM poller ORDER BY id ASC");
    if ($pollers && sizeof($pollers) > 0) {
        foreach ($pollers as $poller) {
            $poller_data = db_fetch_row("SELECT * FROM poller WHERE id = " . $poller["id"]);
        }
    } else {
        /* this is NOT a distributed system, but it should have at least one local poller. */
        $poller_lastrun = read_config_option("poller_lastrun", true);
        $values = array("cactiApplPollerIndex" => 1, "cactiApplPollerHostname" => "localhost", "cactiApplPollerIpAddress" => "127.0.0.1", "cactiApplPollerLastUpdate" => $poller_lastrun);
        $mc->table('cactiApplPollerTable')->row(1)->insert($values);
        $values = array("cactiStatsPollerIndex" => 1, "cactiStatsPollerHostname" => "localhost", "cactiStatsPollerMethod" => read_config_option("poller_type", true));
        $mc->table('cactiStatsPollerTable')->row(1)->insert($values);
    }
    /* add all devices as devicetable entries to the snmp cache */
    $devices = db_fetch_assoc("SELECT id, description, hostname, 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) {
            $device = db_fetch_row("SELECT * FROM host WHERE id = " . $device["id"]);
            /* add device to cactiApplDeviceTable */
            $values = array("cactiApplDeviceIndex" => $device["id"], "cactiApplDeviceDescription" => $device["description"], "cactiApplDeviceHostname" => $device["hostname"], "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"])->insert($values);
            /* add device to cactiStatsDeviceTable */
            $values = array("cactiStatsDeviceIndex" => $device["id"], "cactiStatsDeviceHostname" => $device["hostname"], "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"])->insert($values);
        }
    }
}
Exemple #2
0
                 break;
             } elseif (isset($_POST[$field_name])) {
                 db_execute_prepared('REPLACE INTO settings (name, value) VALUES (?, ?)', array($field_name, get_request_var_post($field_name)));
             }
         } elseif (isset($field_array['items']) && is_array($field_array['items'])) {
             while (list($sub_field_name, $sub_field_array) = each($field_array['items'])) {
                 if (isset($_POST[$sub_field_name])) {
                     db_execute_prepared('REPLACE INTO settings (name, value) VALUES (?, ?)', array($sub_field_name, get_request_var_post($sub_field_name)));
                 }
             }
         } elseif (isset($_POST[$field_name])) {
             db_execute_prepared('REPLACE INTO settings (name, value) VALUES (?, ?)', array($field_name, get_request_var_post($field_name)));
         }
     }
     /* update snmpcache */
     snmpagent_global_settings_update();
     api_plugin_hook_function('global_settings_update');
     raise_message(1);
     /* reset local settings cache so the user sees the new settings */
     kill_session_var('sess_config_array');
     if (isset($_REQUEST['header']) && $_REQUEST['header'] == 'false') {
         header('Location: settings.php?header=false&tab=' . $_POST['tab']);
     } else {
         header('Location: settings.php?tab=' . $_POST['tab']);
     }
     break;
 case 'send_test':
     email_test();
     break;
 default:
     top_header();