tengo un nuevo plugin para Nagios que casi funciona como pretendo
Aquí va el código:
Using perl Syntax Highlighting
- #!perl
- use warnings;
- use strict;
- use File::Find;
- # hash with the nagios errorlevels
- my %ERRORS = (
- 'OK' => 0,
- 'WARNING' => 1,
- 'CRITICAL' => 2,
- 'UNKNOWN' => 3,
- );
- # here we save the number of missed shortcuts in the subroutine _check_path
- my $count = 0;
- # here I keep a list of missing shortcuts in the subroutine _check_path
- my @wrongshortcut ;
- # before running we need a mapping to \\server\share or we will miss some apps
- system("net use M: \\\\server\\share") == 0 or warn "mapping M: drive failed\n" ;
- # get the desktop folder
- my $desktop = "D:\\path\\to\\folder with shortcuts\\" ;
- # find all *.lnk files (case insensitive) in $desktop
- # the find function calls the get_shortcut subroutine in this case
- find(\&get_shortcut, $desktop);
- # subroutine to get all the shortcuts in the folder
- sub get_shortcut {
- #the explorer.lnk shortcut has a strange target, skip it
- next if $_ eq "explorer.lnk" ;
- # process the rest of the shortcuts
- if ($_ =~ /.*\.(lnk)/i) {
- parse_lnk($_);
- }
- }
- # subroutine to get the target path of the *.lnk files
- # gets only one argument, the shortcut location.
- sub parse_lnk {
- my ( $file ) = @_;
- use Win32::Shortcut;
- # create a new shortcut object and load it
- my $link = Win32::Shortcut->new();
- $link->Load($file) or print "$file shortcut not found\n" ;
- # if you need to debug the links and targets, uncomment next line
- #print "$link->{File}\t$link->{Path}\n" ;
- # check the target path of the shortcut
- _check_path( $link->{Path}, $link->{File} );
- # close the shortcut object
- $link->Close();
- }
- # this checks the existance of the target program in the parse_link
- sub _check_path {
- my ( $target ) = @_;
- if ( ! -e $target ) {
- # add 1 to $count
- $count++ ;
- # fill @wrongshortcut with missing target
- push ( @wrongshortcut, $target);
- }
- }
- if ($count == 0) {
- print "$ERRORS{'OK'}\t all shortcuts have valid targets\n";
- }
- else {
- print "$ERRORS{'WARNING'}\t @wrongshortcut is not a valid target\n" ;
- }
- # when we're done, remove the mapping
- system("net use M: /delete") == 0 or warn "could not unmap M: drive\n" ;
Coloreado en 0.003 segundos, usando GeSHi 1.0.8.4
Funciona bien, pero no quiero ver ese mensaje de 'Exiting subroutine via next ... (script line)'
¿Alguna idea?
TIA