Esempio n. 1
0
function get_color_code($array, $int = false)
{
    if ($int) {
        $state = strtolower(return_host_state($array['current_state']));
    } else {
        $state = strtolower($array['current_state']);
    }
    $vals = array('ok', 'up', 'down', 'warning', 'unknown', 'critical', 'pending');
    $str = in_array($state, $vals) ? $state : 'unknown';
    return $str;
}
Esempio n. 2
0
/** expecting host name as $in_hostname
 *
 * processes a host array and sends to the hostdetails.php page
 */
function process_host_detail($in_hostname)
{
    global $NagiosData;
    global $NagiosUser;
    $hd = $NagiosData->get_details_by('host', $in_hostname);
    $hostname = $hd['host_name'];
    if (!$NagiosUser->is_authorized_for_host($hostname)) {
        return false;
    }
    //bail if not authorized
    $duration = calculate_duration($hd['last_state_change']);
    $current_state = return_host_state($hd['current_state']);
    $statetype = return_state_type($hd['state_type']);
    //calculate state
    $current_check = $hd['current_attempt'] . ' of ' . $hd['max_attempts'];
    $date_format = 'M d H:i\\:s\\s Y';
    $last_check = date($date_format, $hd['last_check']);
    $next_check = date($date_format, $hd['next_check']);
    $last_state_change = date($date_format, $hd['last_state_change']);
    if ($hd['last_notification'] == 0) {
        $last_notification = 'Never';
    } else {
        $last_notification = date($date_format, $hd['last_notification']);
    }
    $check_type = $hd['check_type'] == 0 ? 'Active' : 'Passive';
    $check_latency = $hd['check_latency'] . ' seconds';
    $execution_time = $hd['check_execution_time'] . ' seconds';
    $state_change = $hd['percent_state_change'] . '%';
    $membership = check_membership($hostname);
    $state = return_host_state($hd['current_state']);
    //host attributes
    //if else statements generate links for Nagios core commands based on status
    $active_checks = return_enabled($hd['active_checks_enabled']);
    if ($active_checks == 'Enabled') {
        $cmd_active_checks = core_function_link('DISABLE_HOST_CHECK', $hostname);
    } else {
        $cmd_active_checks = core_function_link('ENABLE_HOST_CHECK', $hostname);
    }
    $passive_checks = return_enabled($hd['passive_checks_enabled']);
    if ($passive_checks == 'Enabled') {
        $cmd_passive_checks = core_function_link('DISABLE_PASSIVE_HOST_CHECKS', $hostname);
    } else {
        $cmd_passive_checks = core_function_link('ENABLE_PASSIVE_HOST_CHECKS', $hostname);
    }
    $notifications = return_enabled($hd['notifications_enabled']);
    if ($notifications == 'Enabled') {
        $cmd_notifications = core_function_link('DISABLE_HOST_NOTIFICATIONS', $hostname);
    } else {
        $cmd_notifications = core_function_link('ENABLE_HOST_NOTIFICATIONS', $hostname);
    }
    $flap_detection = return_enabled($hd['flap_detection_enabled']);
    if ($flap_detection == 'Enabled') {
        $cmd_flap_detection = core_function_link('DISABLE_HOST_FLAP_DETECTION', $hostname);
    } else {
        $cmd_flap_detection = core_function_link('ENABLE_HOST_FLAP_DETECTION', $hostname);
    }
    $process_perf_data = return_enabled($hd['process_performance_data']);
    $obsession = return_enabled($hd['obsess_over_host']);
    if ($obsession == 'Enabled') {
        $cmd_obsession = core_function_link('STOP_OBSESSING_OVER_HOST', $hostname);
    } else {
        $cmd_obsession = core_function_link('START_OBSESSING_OVER_HOST', $hostname);
    }
    $add_comment = core_function_link('ADD_HOST_COMMENT', $hostname);
    if ($hd['problem_has_been_acknowledged'] == 0) {
        $cmd_acknowledge = core_function_link('ACKNOWLEDGE_HOST_PROBLEM', $hostname);
        $ack_title = 'Acknowledge Problem';
    } else {
        $cmd_acknowledge = core_function_link('REMOVE_HOST_ACKNOWLEDGEMENT', $hostname);
        $ack_title = 'Remove Acknowledgement';
    }
    $cmd_custom_notification = core_function_link('SEND_CUSTOM_HOST_NOTIFICATION', $hostname);
    $cmd_schedule_downtime = core_function_link('SCHEDULE_HOST_DOWNTIME', $hostname);
    $cmd_schedule_dt_all = core_function_link('SCHEDULE_HOST_SVC_DOWNTIME', $hostname);
    $cmd_schedule_checks = core_function_link('SCHEDULE_HOST_SVC_CHECKS', $hostname);
    $cmd_map = CORECGI . 'statusmap.cgi?host=' . $hostname;
    $core_link = CORECGI . 'extinfo.cgi?type=1&host=' . $hostname;
    $details = array('Host' => $hostname, 'MemberOf' => $membership, 'StatusInformation' => $hd['plugin_output'], 'State' => $current_state, 'Duration' => $duration, 'StateType' => $statetype, 'CurrentCheck' => $current_check, 'LastCheck' => $last_check, 'NextCheck' => $next_check, 'LastStateChange' => $last_state_change, 'LastNotification' => $last_notification, 'CheckType' => $check_type, 'CheckLatency' => $check_latency, 'ExecutionTime' => $execution_time, 'StateChange' => $state_change, 'PerformanceData' => $hd['performance_data'], 'ActiveChecks' => $active_checks, 'PassiveChecks' => $passive_checks, 'Notifications' => $notifications, 'FlapDetection' => $flap_detection, 'ProcessPerformanceData' => $process_perf_data, 'Obsession' => $obsession, 'AddComment' => htmlentities($add_comment), 'MapHost' => htmlentities($cmd_map), 'CmdActiveChecks' => htmlentities($cmd_active_checks), 'CmdPassiveChecks' => htmlentities($cmd_passive_checks), 'CmdNotifications' => htmlentities($cmd_notifications), 'CmdFlapDetection' => htmlentities($cmd_flap_detection), 'CmdObsession' => htmlentities($cmd_obsession), 'CmdAcknowledge' => htmlentities($cmd_acknowledge), 'CmdCustomNotification' => htmlentities($cmd_custom_notification), 'CmdScheduleDowntime' => htmlentities($cmd_schedule_downtime), 'CmdScheduleDowntimeAll' => htmlentities($cmd_schedule_dt_all), 'CmdScheduleChecks' => htmlentities($cmd_schedule_checks), 'AckTitle' => $ack_title, 'CoreLink' => htmlentities($core_link));
    return $details;
}
Esempio n. 3
0
function get_by_state($state, $data, $service = false)
{
    $newdata = array();
    if ($service) {
        foreach ($data as $d) {
            if (return_service_state($d['current_state']) == $state) {
                $newdata[] = $d;
            }
        }
    } else {
        foreach ($data as $d) {
            if (return_host_state($d['current_state']) == $state) {
                $newdata[] = $d;
            }
        }
    }
    return $newdata;
    //		return array_filter($data, create_function('$d', 'return return_service_state($d[\'current_state\']) == \''.$state.'\';'));
    //	else
    //		return array_filter($data, create_function('$d', 'return return_host_state($d[\'current_state\']) == \''.$state.'\';'));
}