LoginHelp/GuideAbout TracPreferences
WikiTimelineRoadmapBrowse SourceView TicketsNew TicketSearchDownloads

Changeset 1298


Ignore:
Timestamp:
04/26/2012 10:14:29 AM (2 years ago)
Author:
corti
Message:

fixed the check on writability of the debug log file

Location:
check_tcptraffic
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • check_tcptraffic/Changes

    r1285 r1298  
     12012-04-26  Matteo Corti  <matteo.corti@id.ethz.ch> 
     2 
     3    * check_tcptraffic: fixed the check on writability of the debug log file 
     4 
    152012-03-13  Matteo Corti  <matteo.corti@id.ethz.ch> 
    26 
  • check_tcptraffic/META.yml

    r1287 r1298  
    2222  Carp: 0 
    2323  English: 0 
     24  File::Basename: 0 
    2425  Nagios::Plugin: 0 
    2526  Nagios::Plugin::Range: 0 
  • check_tcptraffic/Makefile.PL

    r1287 r1298  
    2626requires 'Carp'                      => 0; 
    2727requires 'English'                   => 0; 
     28requires 'File::Basename'            => 0; 
    2829requires 'Nagios::Plugin'            => 0; 
    2930requires 'Nagios::Plugin::Range'     => 0; 
  • check_tcptraffic/check_tcptraffic

    r1289 r1298  
    3131use Carp; 
    3232use English qw(-no_match_vars); 
     33use File::Basename; 
    3334use Nagios::Plugin::Threshold; 
    3435use Nagios::Plugin; 
     
    193194 
    194195    $plugin->nagios_exit( UNKNOWN, 'Cannot determine the user' ); 
     196 
     197    return; 
     198 
     199} 
     200 
     201############################################################################## 
     202# Usage     : assert_is_writable( 'filename' ) 
     203# Purpose   : checks if the file can be written 
     204# Returns   : exits with UNKNOW status if not 
     205# Arguments : n/a 
     206# Throws    : n/a 
     207# Comments  : n/a 
     208# See also  : n/a 
     209sub assert_is_writable { 
     210 
     211    my $filename = shift; 
     212 
     213    if ( -e $filename ) { 
     214        if ( -f $filename ) { 
     215            if ( !-w $filename ) { 
     216                $plugin->nagios_exit( UNKNOWN, 
     217                    "File $filename exists and is not writable" ); 
     218            } 
     219        } 
     220        else { 
     221            $plugin->nagios_exit( UNKNOWN, 
     222                "Cannot write to $filename: exists but is not a regular file" ); 
     223        } 
     224    } 
     225    else { 
     226 
     227        # check the parent directory 
     228        my $directory = dirname($filename); 
     229 
     230        if ( !-e $directory ) { 
     231            $plugin->nagios_exit( UNKNOWN, 
     232"Cannot write to $filename: parent directory $directory does not exist" 
     233            ); 
     234        } 
     235 
     236        if ( !-w $directory ) { 
     237            $plugin->nagios_exit( UNKNOWN, 
     238"Cannot write to $filename: parent directory $directory exists but is not writable" 
     239            ); 
     240        } 
     241 
     242    } 
    195243 
    196244    return; 
     
    464512# Sanity checks 
    465513 
    466 if ( $options->debug_log() && ( !-w $options->debug_log() ) ) { 
    467     $plugin->nagios_exit( UNKNOWN, $options->debug_log() . ' is not writable' ); 
     514if ( $options->debug_log() ) { 
     515    assert_is_writable( $options->debug_log() ); 
    468516} 
    469517debug('------------------------------------------'); 
  • check_tcptraffic/check_tcptraffic.pod

    r1285 r1298  
    104104=item * English 
    105105 
     106=item * File::Basename 
     107 
    106108=item * Nagios::Plugin 
    107109 
  • check_tcptraffic/t/00_modules.t

    r1287 r1298  
    1919use_ok('English'); 
    2020 
     21use_ok('File::Basename'); 
     22can_ok( 'File::Basename', 'dirname' ); 
     23 
    2124use_ok('Nagios::Plugin'); 
    2225can_ok( 'Nagios::Plugin', 'new' ); 
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