perl学习之nagios脚本

发布时间:2020-03-18 12:38:37 作者:woai2607
来源:网络 阅读:732
  1. #!/usr/bin/perl 
  2. use strict; 
  3. use Getopt::Long; 
  4. use LWP::Simple; 
  5. use lib "/usr/lib64/nagios/plugins"
  6. use utils qw ($TIMEOUT %ERRORS &print_revision &support); 
  7. my $HOSTADDRESS; 
  8. Getopt::Long::GetOptions( 
  9.         'h=s' => \$HOSTADDRESS 
  10. ); 
  11. if (defined ($HOSTADDRESS)){ 
  12.         my $content = get("http://$HOSTADDRESS:8080/health.html"); 
  13.                 if ( $content ne '' ){ 
  14.         print "sling is running now!\n"
  15.         exit $ERRORS{'OK'}; 
  16. }else
  17.         print "sling is not running,health page not found!!\n"
  18.         exit $ERRORS{'UNKNOWN'}; 

根据查看的nagios官网,如果用perl写监控脚本,必须使用strict模块,定义的所有变量都必须使用my声明,Getopt::Long模块可以为perl脚本传参,lib是指定nagios里utils.pm的位置,引用utils模块,nagios自带的%ERRORS可以为我们返回状态code。

推荐阅读:
  1. 烂泥:学习Nagios(二):Nagios配置
  2. 烂泥:学习Nagios(一):Nagios安装

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

perl学习 nagios脚本 na

上一篇:laravel cursor的底层实现

下一篇:web前端与后台数据交互

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》