Stoplight ã« Nagios ã®ã¢ã©ã¼ãã表示ãã
複数の Jenkins と Travis のビルドの失敗が最速で分かる Stoplight を Heroku にデプロイ - すえひろがりっっっっ! ã®ç¶ãã
StoplightのIcinga,Monitプロバイダ書いたよー - cynipeと読む ã«ããã¨ç°¡åã«éç¥å ãå¢ãããããã§ãã
ååãè¼ãã iPad ã®ãã®ç»åã
å®ã¯ Nagios ã®æ å ±ã表示ãã¦ãã¾ãã
ä»å㯠Nagios ã®ã¢ã©ã¼ãã表示ããããã®æ¹æ³ã«ã¤ãã¦ã¡ã¢ãã¦ããã¾ãã
ä¸è¨è¨äºã«ãã㨠Nagios ã®æ å ±ã Restful API ã§å ¬éã§ããããã«ãã GitHub - dmytro/nagira: NAGIos Restful Api ã¨ããã®ãããããã§ãããä»åä»æãããµã¼ãã«ã¯ããããã®äºæ ã«ãã Ruby ãå°å ¥ã§ãã¾ããã
ããã«ç¨¼åãã¦ãã Nagios ã®ãã¼ã¸ã§ã³ 2.x ç³»ã¨å¤ãããããã Nagira ã対å¿ãã¦ãã¾ããã§ããã
ããã§ä»åã¯ãã¾ãã¾å ¥ã£ã¦ãã PHP ã§ä»£ç¨ãããã¨ã«ãã¾ããã
PHP ã«ãã nagios ã®æ å ±ã®å ¬é
Nagios ã¯ãµã¼ãã¹ç¶æ³ã status.dat ã¨ãããã¡ã¤ã«ã«åãã®ã§ãããããã¨ã« JSON å½¢å¼ã§å ¬éã§ããããã«ãã¾ãã
<?php // stoplight.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";
ã㨠Apache ãªã©ã® Web ãµã¼ãã§é©å®è¨å®ããã°ã以ä¸ã®ãããªæã㧠HTTP çµç±ã§ä»¥ä¸ã®ãããªæãã§åå¾ã§ããããã«ãªãã¾ãã
{ "åå" : { ... "last_check":"1354097154", ... "current_state":"1", ... }, "åå" : { ... }, ... }
ã¨ãã« PHP ã§ããå¿ è¦ã¯ãªããstatus.dat ã解æã㦠HTTP ã§å ¬éã§ãããã®ã§ããã°ãªãã§ãããã¨æãã¾ãã
Provider ã®è¨è¿°
Stoplight ã« ä¸è¨ã® JSON ãåå¾ããã³ã¼ãã追å ãã¾ãã
https://github.com/customink/stoplight#contributing ã«ãã㨠Stoplight::Providers::Provider ãç¶æ¿ããprojects ã¡ã½ãããå®è£ ããã ãã®è¦ªåè¨è¨ã®ããã§ãã
# lib/stoplight/providers/nagios.rb require 'multi_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 > 0 ? 1 : 0), :current_status => 0, :culprits => [] }) end end end end
ç¶æ¿å ã® Provider ã¯ã©ã¹ã®ã»ãã§ãè¨å®éãã« HTTP ãªã¯ã¨ã¹ããã¦ããã¦ãããã«å¯¾ããã¬ã¹ãã³ã¹ã @response ã«å ¥ã£ã¦ããã®ã§ãããã Stoplight::Project ã«å¤æãã¦è¿ãã¦ãããã°OKã§ãã
失æãæåãã®å¤æ㯠:last_build_status ã®å¤ã§è¡ããã¾ãã
https://github.com/customink/stoplight/blob/master/lib/stoplight/project.rb ãè¦ãéãã0 ãªãæåã1 ãªã失æã¨ãªãã¾ãã
ãã㯠Nagios ã® status.dat ã® current_state ã®å¤ã¨ã¡ããã©ä¸è´ãã¦ããã®ã§ããã®ã¾ã¾æ¸¡ãã¦ãããã ãã§æå¾
éãã«åä½ãã¾ãã
è¨å®
Stoplight ã® config/servers.yml ã«ä»¥ä¸ã®ããã«è¨è¿°ãã¾ãã
- type: 'nagios' url: https://nagios.host.url/stoplight.php username: ãã¼ã·ãã¯èªè¨¼ã¦ã¼ã¶å password: ãã¼ã·ãã¯èªè¨¼ãã¹ã¯ã¼ã
url 㯠Nagios å´ã«è¨ç½®ãã status.dat ã解æãã PHP ã® URL ãè¨å®ãã¾ãã
Stoplight ã® Provider ã¯ã¦ã¼ã¶åã¨ãã¹ã¯ã¼ããè¨å®ãã¦ããã¨ããã¼ã·ãã¯èªè¨¼ãéãã¦ããã¾ãã
PHP å´ã® Web ãµã¼ãã®è¨å®ãªã©ã§ãã¼ã·ãã¯èªè¨¼ã®è¨å®ããã£ã¦ããã¨ããã§ãããã
ã¾ã¨ã
Nagios ã®æ å ±ãæãã¨ããã¯ã¢ãããã¯ã§ãããStoplight èªä½ã¯ãã£ã 18 è¡ã®ã³ã¼ãã追å ããã ã㧠Nagios 対å¿ãããã¨ãã§ããããã«ãªãã¾ããã
åæ§ã«ããªã«ãã®å¤±æãæ¤ç¥ãã¦ãã¡ã³ãã¼ã«ã¢ã©ã¼ããããã¨ãã«ã¯ Stoplight ã® Provider ãä½æããã°ãããã£ã¨å¯¾å¿ã§ãããã§ãã
ä»åã®ã³ã¼ã㯠@mallowlabs ããã« Gist ã«ä¸ãã¦ããã£ãã®ã§ä½ãã®åèã«ãªãã°ã