Example #1
0
 public function getState()
 {
     $hostname = $this->hostname;
     $port = $this->port;
     $protocol = $this->protocol;
     $url = $this->url;
     $ret = NagdashHelpers::fetch_json($hostname, $port, $protocol, $url . "/hosts?" . "Columns=name,state,acknowledged,last_state_change,downtimes,notifications_enabled,current_attempt,max_check_attempts,plugin_output");
     if ($ret["errors"] == true) {
         return $ret["details"];
     }
     $state = $ret["details"]["content"];
     $curl_stats = $ret["curl_stats"];
     $curl_stats["{$hostname}:{$port}"]['objects'] = count($state);
     $munge = [];
     foreach ($state as $host) {
         $host['services'] = [];
         $munge[$host['name']] = $host;
     }
     $state = $munge;
     $ret = NagdashHelpers::fetch_json($hostname, $port, $protocol, $url . "/services?" . "Columns=description,host_name,plugin_output,notifications_enabled," . "downtimes,scheduled_downtime_depth,state,last_state_change," . "current_attempt,max_check_attempts,acknowledged");
     $services = $ret["details"]["content"];
     foreach ($services as $service) {
         $hostname = $service['host_name'];
         if ($state[$hostname]) {
             $state[$hostname]['services'][$service['description']] = $service;
         }
     }
     return ["errors" => false, "details" => $state, "curl_stats" => $curl_stats];
 }
Example #2
0
 /**
  * get the host data from all nagios instances
  *
  * Parameters:
  *  $nagios_hosts   - nagios hosts configuration array
  *  $unwanted_hosts - list of unwanted tags for the user
  *  $api_type       - API type to use
  *
  *  Returns [$state, $api_cols, $errors, $curl_stats]
  */
 static function get_nagios_host_data($nagios_hosts, $unwanted_hosts, $api_type)
 {
     $state = [];
     $errors = [];
     $curl_stats = [];
     $api_cols = [];
     foreach ($nagios_hosts as $host) {
         // Check if the host has been disabled locally
         if (!in_array($host['tag'], $unwanted_hosts)) {
             list($host_state, $api_cols, $local_curl_stats) = NagdashHelpers::fetch_state($host['hostname'], $host['port'], $host['protocol'], $host['url'], $api_type);
             $curl_stats = array_merge($curl_stats, $local_curl_stats);
             if (is_string($host_state)) {
                 $errors[] = "Could not connect to API on host {$host['hostname']}, port {$host['port']}: {$host_state}";
             } else {
                 foreach ($host_state as $this_host => $null) {
                     $host_state[$this_host]['tag'] = $host['tag'];
                 }
                 $state += (array) $host_state;
             }
         }
     }
     return [$state, $api_cols, $errors, $curl_stats];
 }
Example #3
0
foreach ($nagios_hosts as $host) {
    echo ".tag_{$host['tag']}   { background-color: {$host['tagcolour']} }\n";
}
?>
</style>
<?php 
if (isset($extra_css)) {
    echo "<link rel=\"stylesheet\" href=\"{$extra_css}\">";
}
?>
</head>
<body>
  <div id="spinner"><h3><img src="images/ajax-loader.gif" align="absmiddle"> Refreshing...</h3></div>
  <div id="nagioscontainer"></div>
  <?php 
NagdashHelpers::render("settings_dialog.php", ["nagios_hosts" => $nagios_hosts, "unwanted_hosts" => $unwanted_hosts]);
?>


<script>
    $(document).keypress(function(e) {
        if (e.which == 115) { // "s"
            $("#settings_modal").modal();
        }
    });
    $(document).ready(load_nagios_data(<?php 
echo $show_refresh_spinner === true;
?>
));
</script>
</body>
Example #4
0
 public function getState()
 {
     $response = NagdashHelpers::fetch_json($this->hostname, $this->port, $this->protocol, $this->url);
     return $response;
 }
Example #5
0
require_once '../phplib/NagiosApi.php';
require_once '../phplib/NagiosLivestatus.php';
require_once '../phplib/utils.php';
$supported_methods = ["ack", "downtime", "enable", "disable"];
if (!isset($_POST['nag_host'])) {
    echo "Are you calling this manually? This should be called by Nagdash only.";
} else {
    $nagios_instance = $_POST['nag_host'];
    $action = $_POST['action'];
    $details = ["host" => $_POST['hostname'], "service" => $_POST['service'] ? $_POST['service'] : null, "author" => function_exists("nagdash_get_user") ? nagdash_get_user() : "Nagdash", "duration" => $_POST['duration'] ? $_POST['duration'] * 60 : null, "comment" => "{$action} from Nagdash"];
    if (!in_array($action, $supported_methods)) {
        echo "Nagios-api does not support this action ({$action}) yet. ";
    } else {
        foreach ($nagios_hosts as $host) {
            if ($host['tag'] == $nagios_instance) {
                $nagios_api = NagdashHelpers::get_nagios_api_object($api_type, $host["hostname"], $host["port"], $host["protocol"], $host["url"]);
            }
        }
        switch ($action) {
            case "ack":
                $ret = $nagios_api->acknowledge($details);
                break;
            case "downtime":
                $ret = $nagios_api->setDowntime($details);
                break;
            case "enable":
                $ret = $nagios_api->enableNotifications($details);
                break;
            case "disable":
                $ret = $nagios_api->disableNotifications($details);
                break;
Example #6
0
    <h4>Known Service Problems</h4>
    <table class="widetable known_service" id="known_services">
    <tr><th width="30%">Hostname</th><th width="37%">Service</th><th width="18%">State</th><th width="10%">Duration</th><th width="5%">Attempt</th></tr>
<?php 
    foreach ($known_services as $service) {
        if ($service['is_ack']) {
            $status_text = "ack";
        }
        if ($service['is_downtime']) {
            $status_text = "downtime {$service['downtime_remaining']}";
        }
        if (!$service['is_enabled']) {
            $status_text = "disabled";
        }
        echo "<tr class='known_service'>";
        $tag = NagdashHelpers::print_tag($service['tag'], count($nagios_hosts));
        echo "<td>{$service['hostname']} " . $tag . "</td>";
        echo "<td>{$service['service_name']}</td>";
        echo "<td class='{$nagios_service_status_colour[$service['service_state']]}'>{$nagios_service_status[$service['service_state']]} ({$status_text})</td>";
        echo "<td>{$service['duration']}</td>";
        echo "<td>{$service['current_attempt']}/{$service['max_attempts']}</td>";
        echo "</tr>";
    }
    ?>

    </table>
<?php 
}
?>

    </div>