wget -O - http://debmon.org/debmon/repo.key 2>/dev/null | apt-key add - echo 'deb http://debmon.org/debmon debmon-jessie main' >/etc/apt/sources.list.d/debmon.list apt-get update apt-get install icinga2
icinga2 node wizard
service icinga2 reload
service icinga2 checkconfig
icinga2 pki ticket --cn TS01E.PSHOME.local
icinga2 node list icinga2 node update-config service icinga2 reload
object User "icingaadmin" { import "generic-user" display_name = "Icinga 2 Admin" groups = [ "icingaadmins" ] email = "icingaadmin@yandex.ru" } object UserGroup "icingaadmins" { display_name = "Icinga 2 Admin Group" }
apt-get install ssmtp
echo nagios:icingarobot@yandex.ru >> /etc/ssmtp/revaliases
root=postmaster mailhub=smtp.yandex.ru:465 hostname=icinga-failover FromLineOverride=YES AuthUser=icingarobot@yandex.ru AuthPass=password UseTLS=YES
#!/bin/sh curl -F "token=$PUSHOVERTOKEN" \ -F "user=$PUSHOVERUSER" \ -F "title=$PUSHOVERTITLE" \ -F "message=$PUSHOVERMESSAGE" \ -F "html=$PUSHOVERHTML" \ https://api.pushover.net/1/messages exit 0
object NotificationCommand "pushover-host-notification" { import "plugin-notification-command" command = [ SysconfDir + "/icinga2/scripts/pushovernotify.sh" ] env = { PUSHOVERUSER = "$user.vars.pushover_user$" PUSHOVERTOKEN = "$user.vars.pushover_token$" PUSHOVERTITLE = "Icinga2 Host Notification" PUSHOVERMESSAGE = " <b>$notification.type$</b> <a href='http://__/host.php?host=$host.display_name$'>$host.display_name$</a> <b>$host.state$</b> $icinga.long_date_time$" PUSHOVERHTML = "1" } } object NotificationCommand "pushover-service-notification" { import "plugin-notification-command" command = [ SysconfDir + "/icinga2/scripts/notifybypushover2.sh" ] env = { PUSHOVERUSER = "$user.vars.pushover_user$" PUSHOVERTOKEN = "$user.vars.pushover_token$" PUSHOVERTITLE = "Icinga2 Service Notification" PUSHOVERMESSAGE = " <b>$notification.type$</b> <a href='http://__/host.php?host=$host.display_name$'>$host.display_name$</a> $service.display_name$ <b>$service.state$</b> $icinga.long_date_time$" PUSHOVERHTML = "1" } }
template Notification "pushover-host-notification" { command = "pushover-host-notification" states = [ Up, Down ] types = [ Problem, Acknowledgement, Recovery, Custom, FlappingStart, FlappingEnd, DowntimeStart, DowntimeEnd, DowntimeRemoved ] period = "24x7" } template Notification "pushover-service-notification" { command = "pushover-service-notification" states = [ OK, Warning, Critical, Unknown ] types = [ Problem, Acknowledgement, Recovery, Custom, FlappingStart, FlappingEnd, DowntimeStart, DowntimeEnd, DowntimeRemoved ] period = "24x7" }
apply Notification "pushover-icingaadmin" to Host { import "pushover-host-notification" user_groups = host.vars.notification.mail.groups users = host.vars.notification.mail.users assign where host.vars.notification.mail interval = 0 // disable re-notification } apply Notification "pushover-icingaadmin" to Service { import "pushover-service-notification" user_groups = host.vars.notification.mail.groups users = host.vars.notification.mail.users assign where host.vars.notification.mail interval = 0 // disable re-notification }
object User "icingaadmin" { import "generic-user" display_name = "Icinga 2 Admin" groups = [ "icingaadmins" ] email = "icingaadmin@yandex.ru" vars.pushover_user = "1111111111111111111111111111111" vars.pushover_token = "1111111111111111111111111111111" }
<?php require_once( "config.php" ); if (!empty($_GET['host'])) { $host = trim($_GET['host']); $json_url = "https://".ICINGA2_HOST.":5665/v1/objects/hosts/".$host."/"; try { $ch = curl_init(); if (FALSE === $ch) throw new Exception('failed to initialize'); curl_setopt($ch, CURLOPT_URL, $json_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); $content = curl_exec($ch); echo $content; if (FALSE === $content) throw new Exception(curl_error($ch), curl_errno($ch)); } catch(Exception $e) { trigger_error(sprintf( 'Curl failed with error #%d: %s', $e->getCode(), $e->getMessage()), E_USER_ERROR); } } else { if (!empty($_GET['domain'])) { $domain = trim($_GET['domain']); $json_url = "https://".ICINGA2_HOST.":5665/v1/objects/hosts?filter=match%28%22*" . $domain . "*%22%2Chost%2Ename%29"; } else { $json_url = "https://".ICINGA2_HOST.":5665/v1/objects/hosts"; } try { $ch = curl_init(); if (FALSE === $ch) throw new Exception('failed to initialize'); curl_setopt($ch, CURLOPT_URL, $json_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); $content = curl_exec($ch); echo $content; if (FALSE === $content) throw new Exception(curl_error($ch), curl_errno($ch)); } catch(Exception $e) { trigger_error(sprintf( 'Curl failed with error #%d: %s', $e->getCode(), $e->getMessage()), E_USER_ERROR); } } ?>
$(document).ready(function () { $('#get-data').click(function () { var showData = $('#show-data'); var www_path = ""; var json_url = 'icinga-proxy.php?domain=' + domainFilter.value; $.getJSON(json_url, function (data) { var data0 = data.results; var items = data0.map(function (item) { var hostdown = item.attrs.state; var icon_image_src = item.attrs.icon_image; var hostdown_bage; var hostdown_bage_span; if (hostdown == 1) { hostdown_bage = "<span class='mdl-badge mdl-badge--overlap' data-badge='!'>"; hostdown_bage_span = "</span>"; icon_image_src = item.attrs.icon_image.slice(0, -4) + "_gray.png"; } else { hostdown_bage = ""; hostdown_bage_span = ""; if (item.attrs.icon_image) { icon_image_src = item.attrs.icon_image; } else { icon_image_src = "img/my/dot.png"; } } return "<td class='mdl-data-table__cell--non-numeric'><img src='" + www_path + icon_image_src + "' id='host" + item.attrs.display_name.split('.')[0] + "' />" + "<div class='mdl-tooltip' for='host" + item.attrs.display_name.split('.')[0] + "'>" + item.attrs.display_name + "</div>" + hostdown_bage_span + "</td><td class='mdl-data-table__cell--non-numeric' onclick='location=\"host.php?host=" + item.attrs.__name + "\"'>" + hostdown_bage + hostdown_bage_span + item.attrs.display_name + "</td>" + "<td class='mdl-data-table__cell--non-numeric'>" + item.attrs.vars.domain_name + "</td>" //+ "<td class='mdl-data-table__cell--non-numeric'>" + item.attrs.vars.os + "</td>" ; }); showData.empty(); if (items.length) { var content = '<tr>' + items.join('</tr><tr>') + '</tr>'; var list = $('<table class="mdl-data-table mdl-js-data-table" style="margin: auto; width: 100%" />').html(content); showData.append(list); } }); showData.text('Loading the JSON file.'); }); $('#get-data').click(); setInterval(function(){$('#get-data').click();},60*1000); });
Source: https://habr.com/ru/post/307358/
All Articles