首页 > 代码库 > icinga2通过check_ping.pl插件生成可用性监控

icinga2通过check_ping.pl插件生成可用性监控


icinga2通过check_ping.pl插件生成可用性监控


下载地址:


https://exchange.nagios.org/directory/Plugins/Network-Protocols/ICMP/check_ping-2Epl/details



修改脚本:


# vi check_ping.pl(最后2行改成下面这样)



my $loss = sprintf("%.3f",(100 - (100 * $nok/$pack)));


printf("PING - Packet active = $loss%%, rta = $rta ms\n|active=$loss", $loss,$rta,$loss);



:wq



解释:


1、(100 - (100 * $nok/$pack))表示的可用性(100% - 丢包率)

2、%.3f表示保留3个小数点

3、增加|active=$loss及最后的$loss是为生成图像(grafana里用得到)



在icinga2里调用check_ping.pl插件


# vi /etc/icinga2/conf.d/templates.conf 


object CheckCommand "check-ping" {

  import "plugin-check-command"

  command = [ PluginDir + "/check_ping.pl" ]

  arguments = {

  "--host" = "$address$"

  "--loss" = "$loss$"

  "--rta" = "$rta$"

}

}


:wq



# vi /etc/icinga2/conf.d/services.conf


apply Service "check_ping" {

  import "generic-service"


  check_command = "check-ping"

vars.loss="900,1000"

  vars.rta="900,1000"

  vars.perf = true

  assign where host.vars.os == "git"


}


:wq



# service icinga2 restart





本文出自 “linux” 博客,请务必保留此出处http://yangzhiming.blog.51cto.com/4849999/1893018

icinga2通过check_ping.pl插件生成可用性监控