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。