LoginHelp/GuideAbout TracPreferences
WikiTimelineRoadmapBrowse SourceView TicketsNew TicketSearchDownloads

Changeset 860


Ignore:
Timestamp:
10/31/2007 01:48:16 PM (6 years ago)
Author:
corti
Message:

new packaging (based on ExtUtils::MakeMaker?, compatible with embedded Perl, used Nagios::Plugin

Location:
check_writable
Files:
4 edited
1 moved

Legend:

Unmodified
Added
Removed
  • check_writable/Changes

    r747 r860  
     12007-10-31  Matteo Corti  <matteo.corti@id.ethz.ch> 
     2 
     3    * check_writable: embedded Perl compatibility 
     4    * check_writable: new packaging 
     5    * check_writable: uses Nagios::Plugin 
  • check_writable/NEWS

    r759 r860  
    1 2007-07-26 Initial release (1.0) 
     12007-10-31 Version 2.0.0: new packaging (based on ExtUtils::MakeMaker, compatible with embedded Perl, used Nagios::Plugin 
     2 
     32007-07-26 Version 1.0.0: initial release 
  • check_writable/VERSION

    r814 r860  
    1 1.0.0 
     12.0.0 
  • check_writable/check_writable

    • Property svn:keywords set to Id Revision HeadURL Source Date
    r816 r860  
    1 #!/usr/bin/perl 
    2  
    3 # ETH Zurich / Informatikdienste 
    4 # Matteo Corti <matteo.corti@gmail.com> 
    5  
     1#!perl 
     2 
     3# check_writable is a Nagios plugin that checks if one or more 
     4# directories are writable by: 
     5# 
     6# - checking that the supplied directory is indeed a directory 
     7# - checking if the the filesystem permissions are OK 
     8# - creating a temporary file 
     9# - writing random data to the temporary file (and reading it back) 
     10# 
     11# It return a critical status if one of the tests fails 
     12# 
     13# See  the INSTALL file for installation instructions 
     14# 
     15# Copyright (c) 2007, ETH Zurich. 
     16# 
     17# This module is free software; you can redistribute it and/or modify it 
     18# under the terms of GNU general public license (gpl) version 3. 
     19# See the LICENSE file for details. 
     20# 
     21# RCS information 
     22# enable substitution with: 
     23#   $ svn propset svn:keywords "Id Revision HeadURL Source Date" 
     24# 
     25#   $Id$ 
     26#   $Revision$ 
     27#   $HeadURL$ 
     28#   $Date$ 
     29 
     30use 5.008; 
    631use strict; 
    732use warnings; 
    8  
     33use Carp; 
     34 
     35use version; our $VERSION = '2.0.0'; 
     36 
     37use Data::Random; 
     38use English qw(-no_match_vars); 
    939use File::Temp; 
    1040use Getopt::Long; 
    11 use Data::Random; 
    12      
    13 my $VERSION    = '1.0.0'; 
    14  
    15 my $prog_name  = "WRITEABLE"; 
    16  
    17 ############################################################################## 
    18 # subroutines 
    19  
    20 ################################ 
    21 # prints the usage of the plugin 
    22 sub usage { 
    23   my $msg = shift; 
    24  
    25   if (defined $msg) { 
    26       print "$msg\n"; 
    27   } 
    28  
    29   print " 
    30 usage: check_writeable --dir DIRECTORY 
    31  
    32   -?, --help      help 
    33   -d, --dir       directory to check 
    34   -v, --verbose   verbose output 
    35   --version       prints $prog_name version and exits 
    36  
    37 "; 
    38    
    39   exit(3); 
    40 } 
     41use Nagios::Plugin::Threshold; 
     42use Nagios::Plugin; 
     43use Pod::Usage qw(pod2usage); 
     44 
     45# IMPORTANT: Nagios plugins could be executed using embedded perl in this case 
     46#            the main routine would be executed as a subroutine and all the 
     47#            declared subroutines would therefore be inner subroutines 
     48#            This will cause all the global lexical variables not to stay shared 
     49#            in the subroutines! 
     50# 
     51# All variables are therefore declared as package variables... 
     52# 
     53use vars qw( 
     54  $plugin 
     55  $result 
     56  $verbose 
     57  @dir 
     58  @errors 
     59); 
    4160 
    4261############################################################################## 
     
    4463# 
    4564 
    46 my $result; 
    47 my @dir; 
    48 my $verbose; 
    49  
    50  
    51 my @errors; 
     65################ 
     66# Initialization 
     67$plugin = Nagios::Plugin->new( shortname => 'CHECK_WRITABLE' ); 
    5268 
    5369######################## 
    5470# Command line arguments 
    5571 
    56 Getopt::Long::Configure ("bundling"); 
    57 $result = GetOptions ( 
    58     "dir|d=s"       => \@dir, 
    59     "help|?"        => sub { usage() }, 
    60     "verbose|v+"    => \$verbose, 
    61     "version"       => sub { print "check_writeable version $VERSION\n"; exit 3;} 
     72Getopt::Long::Configure(qw{bundling}); 
     73$result = GetOptions( 
     74    'dir|d=s'    => \@dir, 
     75    'help|?'     => sub { pod2usage(); }, 
     76    'verbose|v+' => \$verbose, 
     77    'version'    => sub { print "check_writeable version $VERSION\n"; exit 3; } 
    6278); 
    6379 
    64 if (!$result) { 
    65   usage(); 
     80if ( !$result ) { 
     81    pod2usage(); 
    6682} 
    6783 
    68 if (! @dir) { 
    69     die "at least one directory has to be specified"; 
     84if ( !@dir ) { 
     85    pod2usage( -message => 'at least one directory has to be specified' ); 
    7086} 
    7187 
    72 File::Temp->safe_level( File::Temp::HIGH ); 
     88File::Temp->safe_level(File::Temp::HIGH); 
    7389 
    7490foreach my $dir (@dir) { 
     
    7995 
    8096    # 1) check FS permissions 
    81      
    82     if (!-d $dir) { 
     97 
     98    if ( !-d $dir ) { 
    8399        push @errors, "'$dir' is not a directory"; 
    84100        next; 
    85     } elsif (!-w $dir || !-W $dir) { 
     101    } 
     102    elsif ( !-w $dir || !-W $dir ) { 
    86103        push @errors, "'$dir' is not writable"; 
    87104        next; 
     
    89106 
    90107    # 2) try to create a temporary file 
    91      
     108 
    92109    my $tmp = new File::Temp( 
    93110        TEMPLATE => 'writetest-XXXXX', 
    94111        DIR      => $dir, 
    95         CLEANUP => 1             
     112        CLEANUP  => 1 
    96113    ); 
    97      
     114 
    98115    if ($verbose) { 
    99116        print "Creating $tmp\n"; 
     
    102119    # 3) try to write to the file 
    103120 
    104     my $random_chars = join('',Data::Random::rand_chars( set => 'all', size => 32 )); 
    105      
    106     print $tmp $random_chars; 
    107  
    108     close $tmp; 
    109      
     121    my $random_chars = 
     122      join q{}, Data::Random::rand_chars( set => 'all', size => 32 ) ; 
     123 
     124    print { $tmp } $random_chars; 
     125 
     126    close $tmp or 
     127        $plugin->nagios_exit(UNKNOWN, "Cannot close $tmp: $OS_ERROR"); 
     128 
    110129    # 4) read the content back and check it 
    111130 
    112     if (!open(IN, $tmp->filename)) { 
     131    my $IN; 
     132    if ( ! open $IN, q{<}, $tmp->filename ) { 
    113133        push @errors, "Cannot read temporary file in $dir"; 
    114134        next; 
    115135    } 
    116136 
    117     while(<IN>) { 
    118         if ($_ ne $random_chars) { 
     137    while (<$IN>) { 
     138        if ( $_ ne $random_chars ) { 
    119139            push @errors, "R/W error on temporary file in $dir"; 
    120140        } 
     
    122142    } 
    123143 
    124     close IN; 
     144    close $IN or 
     145        $plugin->nagios_exit(UNKNOWN, "Cannot close $tmp: $OS_ERROR"); 
     146 
     147} 
     148 
     149if (@errors) { 
     150    $plugin->nagios_exit( CRITICAL, join q{ }, @errors ); 
     151} 
     152 
     153$plugin->nagios_exit( OK, join q{ }, @dir ); 
     154 
     1551; 
     156 
     157__END__ 
     158 
     159=pod 
     160 
     161=head1 NAME 
     162 
     163C<check_writable> is a Nagios plugin that checks if one or more 
     164directories are writable. 
     165 
     166=head1 DESCRIPTION 
     167 
     168C<check_writable> is a Nagios plugin that checks if one or more 
     169directories are writable by: 
     170 
     171 - checking that the supplied directory is indeed a directory 
     172 - checking if the the filesystem permissions are OK 
     173 - creating a temporary file 
     174 - writing random data to the temporary file (and reading it back) 
     175 
     176It return a critical status if one of the tests fails 
     177 
     178=head1 VERSION 
     179 
     180Version 2.0.0 
     181 
     182=head1 SYNOPSIS 
     183 
     184 check_writeable --dir=DIRECTORY 
     185 
     186 Options: 
     187  --help,-h,-?                  this help message 
     188  --dir,-d                      directory to check 
     189  --verbose,-v                  verbose output 
     190  --version                     prints version and exits 
     191 
     192=head1 REQUIRED ARGUMENTS 
     193 
     194--dir 
     195 
     196=head1 OPTIONS 
     197 
     198  --help,-h,-?                  this help message 
    125199     
    126 } 
    127  
    128 if (@errors) { 
    129     print "$prog_name CRITICAL - ".join(" ",@errors)."\n"; 
    130     exit(2); 
    131 } 
    132  
    133 print "$prog_name OK - ".join(" ", @dir),"\n"; 
    134  
    135 exit(0); 
    136  
    137 1; 
    138  
    139 __END__ 
     200  --dir,-d                      directory to check 
     201     
     202  --verbose,-v                  verbose output 
     203     
     204  --version                     prints version and exits 
     205 
     206=head1 EXAMPLE 
     207 
     208check_dir --dir=/tmp 
     209 
     210check_diskio checks if /tmp is writable 
     211 
     212=head1 DIAGNOSTICS 
     213 
     214You can specify multiple --verbose options to increase the program 
     215verbosity. 
     216 
     217=head1 EXIT STATUS 
     218 
     2190 if OK, 1 in case of a warning, 2 in case of a critical status and 3 
     220in case of an unkown problem 
     221 
     222=head1 DEPENDENCIES 
     223 
     224check_writable depends on 
     225 
     226=over 4 
     227 
     228=item * Carp 
     229 
     230=item * Data::Random 
     231 
     232=item * File::Temp 
     233 
     234=item * English 
     235 
     236=item * Getopt::Long 
     237 
     238=item * Nagios::Plugin 
     239 
     240=item * Nagios::Plugin::Threshold 
     241 
     242=item * POSIX 
     243 
     244=item * Pod::Usage 
     245 
     246=item * version 
     247 
     248=back 
     249 
     250=head1 CONFIGURATION 
     251 
     252=head1 INCOMPATIBILITIES 
     253 
     254None reported. 
     255 
     256=head1 SEE ALSO 
     257 
     258Nagios documentation 
     259 
     260=head1 BUGS AND LIMITATIONS 
     261 
     262No bugs have been reported. 
     263 
     264Please report any bugs or feature requests to matteo.corti@id.ethz.ch, 
     265or through the web interface at 
     266https://svn.id.ethz.ch/trac/bd_webhosting/newticket 
     267 
     268=head1 AUTHOR 
     269 
     270Matteo Corti <matteo.corti@id.ethz.ch> 
     271 
     272=head1 LICENSE AND COPYRIGHT 
     273 
     274Copyright (c) 2007, ETH Zurich. 
     275 
     276This module is free software; you can redistribute it and/or modify it 
     277under the terms of GNU general public license (gpl) version 3. 
     278See the LICENSE file for details. 
     279 
     280=head1 DISCLAIMER OF WARRANTY 
     281 
     282BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 
     283FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT 
     284WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER 
     285PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, 
     286EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 
     287IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
     288PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 
     289SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME 
     290THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. 
     291 
     292IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 
     293WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 
     294REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE 
     295TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR 
     296CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 
     297SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 
     298RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 
     299FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 
     300SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
     301DAMAGES. 
     302 
     303=head1 ACKNOWLEDGMENTS 
  • check_writable/check_writable.spec

    r814 r860  
    1 %define version 1.0.0 
     1%define version 2.0.0 
    22%define release 0 
    33%define name    check_writable 
     
    4646 
    4747%changelog 
     48* Wed Oct 31 2007 Matteo Corti <matteo.corti@id.ethz.ch> - 2.0.0-0 
     49- updated to 2.0.0 
     50 
    4851* Mon Sep 24 2007 Matteo Corti <matteo.corti@id.ethz.ch> - 1.0.0-0 
    4952- first rpm package 
Note: See TracChangeset for help on using the changeset viewer.
 

Wichtiger Hinweis:
Diese Website wird in älteren Versionen von Netscape ohne graphische Elemente dargestellt. Die Funktionalität der Website ist aber trotzdem gewährleistet. Wenn Sie diese Website regelmässig benutzen, empfehlen wir Ihnen, auf Ihrem Computer einen aktuellen Browser zu installieren. Weitere Informationen finden Sie auf
folgender Seite.

Important Note:
The content in this site is accessible to any browser or Internet device, however, some graphics will display correctly only in the newer versions of Netscape. To get the most out of our site we suggest you upgrade to the newer browser.
More information

 
© 2005 ETH Zürich | Imprint | 26.09.2007 | Version 0.12
top