Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use LWP::Simple;
- use Getopt::Long;
- use lib "/usr/share/nagios/libexec";
- use utils qw($TIMEOUT %ERRORS &usage &support &print_revision);
- my $PROGNAME="check_hp_supply_info";
- my $VERSION="1.0";
- my $opt_V = undef;
- my $opt_h = undef;
- my $opt_H = undef;
- Getopt::Long::Configure('bundling');
- GetOptions
- ( 'v' => \$opt_V, "version" => \$opt_V,
- 'h' => \$opt_h, "help" => \$opt_h,
- 'H=s' => \$opt_H, "hostname=s" => \$opt_H,
- );
- if ( $opt_V ) {
- print_revision($PROGNAME, $VERSION);
- exit $ERRORS{'OK'};
- }
- if ( $opt_h ) {
- print_help();
- exit $ERRORS{'OK'};
- }
- ($opt_H) || usage("You must specify a hostname\n");
- sub print_help () {
- print_revision($PROGNAME,$VERSION);
- print "Copyright (c) 2010 Mariusz Derela\n\n";
- print_usage();
- support();
- }
- sub print_usage () {
- print "Example: ./$PROGNAME -H 192.168.0.1\n\n";
- print "-H or hostname=NAME\t Hostname\n";
- }
- my $page = &get("http://$opt_H/hp/device/this.LCDispatcher?nav=hp.Supplies");
- usage ("Nie uzyskalem informacji") if (! $page) ;
- if ($page =~ m/(20\d{6})/) {
- my $data=$1;$data =~ s/(\d{4})(\d{2})(\d{2})/\1-\2-\3/;
- printf "Toner wymieniono $data";
- exit $ERRORS{'OK'};
- } else {
- print "Nie uzyskalem informacji";
- exit $ERRORS{'WARNING'};
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement