Skip to content

Instantly share code, notes, and snippets.

@mallowlabs
Created November 29, 2012 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mallowlabs/4165821 to your computer and use it in GitHub Desktop.
Save mallowlabs/4165821 to your computer and use it in GitHub Desktop.
Stoplight Provider for Nagios 2
<?php
$lines = file("/var/log/nagios/status.dat");
echo "{\n";
$processing_service = false;
$json = "";
$host_name = "";
$service_name = "";
for ($i = 0; $i < count($lines); $i++) {
$line = $lines[$i];
if (strpos($line, "service {") === 0) {
$processing_service = true;
} else if ($processing_service && strpos($line, "\t}") === 0) {
$processing_service = false;
echo "\"" . $host_name . " - " . $service_name . "\" : { \n";
echo substr($json, 0, -2);
echo "\n}";
if (count($lines) - 2 != $i) {
echo ",";
}
echo "\n";
$json = "";
}
if ($processing_service) {
$array = split("=", $line);
if (count($array) >= 2) {
$left = trim($array[0]);
$right = trim($array[1]);
if (strcmp($left, "host_name") === 0) {
$host_name = $right;
} else if (strcmp($left, "service_description") === 0) {
$service_name = "$right";
}
$json .= " \"";
$json .= $left;
$json .= "\":\"";
$json .= trim($array[1]);
$json .= "\",\n";
}
}
}
echo "}\n";
require 'json'
module Stoplight::Providers
class Nagios < Provider
def projects
JSON.parse(@response.body).map do |name, service|
Stoplight::Project.new({
:name => name,
:build_url => '',
:last_build_id => '',
:last_build_time => Time.at(service['last_check'].to_i).strftime('%Y-%m-%d %H:%M:%S'),
:last_build_status => service['current_state'].to_i,
:current_status => 0,
:culprits => []
})
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment