Advertisement
Guest User

Untitled

a guest
Jul 13th, 2010
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.20 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use LWP::Simple;
  4. use Getopt::Long;
  5.  
  6. use lib "/usr/share/nagios/libexec";
  7. use utils qw($TIMEOUT %ERRORS &usage &support &print_revision);
  8.  
  9.  
  10. my $PROGNAME="check_hp_supply_info";
  11. my $VERSION="1.0";
  12. my $opt_V = undef;
  13. my $opt_h = undef;
  14. my $opt_H = undef;
  15.  
  16. Getopt::Long::Configure('bundling');
  17. GetOptions
  18.     ( 'v' => \$opt_V, "version" => \$opt_V,
  19.       'h' => \$opt_h, "help" => \$opt_h,
  20.       'H=s' => \$opt_H, "hostname=s" => \$opt_H,
  21.     );
  22.  
  23. if ( $opt_V ) {
  24.     print_revision($PROGNAME, $VERSION);
  25.     exit $ERRORS{'OK'};
  26. }
  27.  
  28. if ( $opt_h ) {
  29.     print_help();
  30.     exit $ERRORS{'OK'};
  31. }
  32.  
  33.  
  34. ($opt_H) || usage("You must specify a hostname\n");
  35.  
  36. sub print_help () {
  37.     print_revision($PROGNAME,$VERSION);
  38.     print "Copyright (c) 2010 Mariusz Derela\n\n";
  39.     print_usage();
  40.     support();
  41. }
  42.  
  43. sub print_usage () {
  44.     print "Example: ./$PROGNAME -H 192.168.0.1\n\n";
  45.     print "-H or hostname=NAME\t Hostname\n";
  46. }
  47.  
  48.  
  49. my $page = &get("http://$opt_H/hp/device/this.LCDispatcher?nav=hp.Supplies");
  50. usage ("Nie uzyskalem informacji") if (! $page) ;
  51.  
  52. if ($page =~ m/(20\d{6})/) {
  53.     my $data=$1;$data =~ s/(\d{4})(\d{2})(\d{2})/\1-\2-\3/;
  54.     printf "Toner wymieniono $data";
  55.     exit $ERRORS{'OK'};
  56. } else {
  57.     print "Nie uzyskalem informacji";
  58.     exit $ERRORS{'WARNING'};
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement