return "Enabled";
        } else {
            return "Disabled";
        }
    } else {
        return "no service name";
    }
}
?>

<?php 
echo "<h3>Service Status</h3>";
?>

<table class='summarySection'>
  <tr>
    <td class='summaryKey'> Radius </td>
    <td class='summaryValue'><span class='sleft'><?php 
echo check_service("radius");
?>
</span> </td>
  </tr>
  <tr>
    <td class='summaryKey'> Mysql </td>
    <td class='summaryValue'><span class='sleft'><?php 
echo check_service("mysql");
?>
</span> </td>
  </tr>
</table>
示例#2
0
function poll_service($service)
{
    global $config;
    $update = array();
    $old_status = $service['service_status'];
    $check_cmd = "";
    // if we have a script for this check, use it.
    $check_script = $config['install_dir'] . '/includes/services/check_' . strtolower($service['service_type']) . '.inc.php';
    if (is_file($check_script)) {
        include $check_script;
    }
    // If we do not have a cmd from the check script, build one.
    if ($check_cmd == "") {
        $check_cmd = $config['nagios_plugins'] . "/check_" . $service['service_type'] . " -H " . ($service['service_ip'] ? $service['service_ip'] : $service['hostname']);
        $check_cmd .= " " . $service['service_param'];
    }
    $service_id = $service['service_id'];
    // Some debugging
    d_echo("\nNagios Service - {$service_id}\n");
    // the check_service function runs $check_cmd through escapeshellcmd, so
    // echo the command as it will be run after being escaped
    $escaped_check_cmd = escapeshellcmd($check_cmd);
    d_echo("Request:  {$escaped_check_cmd}\n");
    list($new_status, $msg, $perf) = check_service($check_cmd);
    d_echo("Response: {$msg}\n");
    // If we have performance data we will store it.
    if (count($perf) > 0) {
        // Yes, We have perf data.
        $rrd_name = array('services', $service_id);
        // Set the DS in the DB if it is blank.
        $DS = array();
        foreach ($perf as $k => $v) {
            $DS[$k] = $v['uom'];
        }
        d_echo("Service DS: " . _json_encode($DS) . "\n");
        if ($service['service_ds'] == "") {
            $update['service_ds'] = json_encode($DS);
        }
        // rrd definition
        $rrd_def = array();
        foreach ($perf as $k => $v) {
            if ($v['uom'] == 'c') {
                // This is a counter, create the DS as such
                $rrd_def[] = "DS:" . $k . ":COUNTER:600:0:U";
            } else {
                // Not a counter, must be a gauge
                $rrd_def[] = "DS:" . $k . ":GAUGE:600:0:U";
            }
        }
        // Update data
        $fields = array();
        foreach ($perf as $k => $v) {
            $fields[$k] = $v['value'];
        }
        $tags = compact('service_id', 'rrd_name', 'rrd_def');
        //TODO not sure if we have $device at this point, if we do replace faked $device
        data_update(array('hostname' => $service['hostname']), 'services', $tags, $fields);
    }
    if ($old_status != $new_status) {
        // Status has changed, update.
        $update['service_changed'] = time();
        $update['service_status'] = $new_status;
        $update['service_message'] = $msg;
    }
    if ($service['service_message'] != $msg) {
        // Message has changed, update.
        $update['service_message'] = $msg;
    }
    if (count($update) > 0) {
        edit_service($update, $service['service_id']);
    }
    return true;
}
示例#3
0
function poll_service($service)
{
    global $config;
    $update = array();
    $old_status = $service['service_status'];
    $check_cmd = "";
    // if we have a script for this check, use it.
    $check_script = $config['install_dir'] . '/includes/services/check_' . strtolower($service['service_type']) . '.inc.php';
    if (is_file($check_script)) {
        include $check_script;
    }
    // If we do not have a cmd from the check script, build one.
    if ($check_cmd == "") {
        $check_cmd = $config['nagios_plugins'] . "/check_" . $service['service_type'] . " -H " . ($service['service_ip'] ? $service['service_ip'] : $service['hostname']);
        $check_cmd .= " " . $service['service_param'];
    }
    // Some debugging
    d_echo("\nNagios Service - " . $service['service_id'] . "\n");
    d_echo("Request:  " . $check_cmd . "\n");
    list($new_status, $msg, $perf) = check_service($check_cmd);
    d_echo("Response: " . $msg . "\n");
    // If we have performance data we will store it.
    if (count($perf) > 0) {
        // Yes, We have perf data.
        $filename = "services-" . $service['service_id'] . ".rrd";
        $rrd_filename = $config['rrd_dir'] . "/" . $service['hostname'] . "/" . safename($filename);
        // Set the DS in the DB if it is blank.
        $DS = array();
        foreach ($perf as $k => $v) {
            $DS[$k] = $v['uom'];
        }
        d_echo("Service DS: " . _json_encode($DS) . "\n");
        if ($service['service_ds'] == "") {
            $update['service_ds'] = json_encode($DS);
        }
        // Create the RRD
        if (!file_exists($rrd_filename)) {
            $rra = "";
            foreach ($perf as $k => $v) {
                if ($v['uom'] == 'c') {
                    // This is a counter, create the DS as such
                    $rra .= " DS:" . $k . ":COUNTER:600:0:U";
                } else {
                    // Not a counter, must be a gauge
                    $rra .= " DS:" . $k . ":GAUGE:600:0:U";
                }
            }
            rrdtool_create($rrd_filename, $rra . $config['rrd_rra']);
        }
        // Update RRD
        $rrd = array();
        foreach ($perf as $k => $v) {
            $rrd[$k] = $v['value'];
        }
        rrdtool_update($rrd_filename, $rrd);
    }
    if ($old_status != $new_status) {
        // Status has changed, update.
        $update['service_changed'] = time();
        $update['service_status'] = $new_status;
        $update['service_message'] = $msg;
    }
    if ($service['service_message'] != $msg) {
        // Message has changed, update.
        $update['service_message'] = $msg;
    }
    if (count($update) > 0) {
        edit_service($update, $service['service_id']);
    }
    return true;
}