Changeset 277 for trunk/dasscm


Ignore:
Timestamp:
Mar 6, 2009, 5:25:20 PM (15 years ago)
Author:
joergs
Message:

added check for nagios plugin

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dasscm/dasscm

    r276 r277  
    2727my $RETURN_OK  = 0;
    2828my $RETURN_NOK = 1;
     29
     30# Nagios return codes
     31my $RETURN_WARN = 1;
     32my $RETURN_CRIT = 2;
     33my $RETURN_UNKNOWN = 3;
    2934
    3035# file to store permissions
     
    8893    print "   diff <path>\n";
    8994    print "   status <path>\n";
     95    print "   check\n";
    9096    print "   cleanup\n";
    9197    print "   permissions\n";
     
    10231029        if (%removedfiles) {
    10241030            print "deleted files (found in repository, but not in system):\n";
    1025             foreach my $key ( values %removedfiles ) {
     1031            foreach my $key ( keys %removedfiles ) {
    10261032                print "$key\n";
    10271033            }
     
    10431049}
    10441050
     1051#
     1052# return short status in Nagios plugin conform way
     1053#
     1054sub check()
     1055{
     1056    check_env();
     1057
     1058    # return code for the shell
     1059    # default: error
     1060    my $return_code = $RETURN_OK;
     1061    my $return_string = "OK: no modified files";
     1062
     1063    ( my $refChangedFiles, my $refRemovedFiles ) =
     1064      getModifiedFiles( "/" );
     1065    my %changedfiles = %{$refChangedFiles};
     1066    my %removedfiles = %{$refRemovedFiles};
     1067
     1068    if ( %removedfiles or %changedfiles ) {
     1069        $return_string = "Warning: ";
     1070        if( %changedfiles ) {
     1071            $return_string .= "changed: " . join( ", ", ( keys %changedfiles ) ) . ". ";
     1072        }
     1073        if( %removedfiles ) {
     1074            $return_string .= "removed: " . join( ", ", ( keys %removedfiles ) ) . ". ";
     1075        }
     1076        $return_code = $RETURN_WARN;
     1077    }
     1078
     1079    # addition nagios Service Status
     1080    #Critical
     1081    #Unknown
     1082
     1083    print $return_string . "\n";
     1084    return $return_code;
     1085}
     1086
     1087
    10451088sub permissions()
    10461089{
    1047     check_parameter( @_, 1 );
    10481090    check_env();
    10491091
     
    10951137sub cleanup()
    10961138{
    1097     check_parameter( @_, 1 );
    10981139    check_env();
    10991140
     
    11841225        $command     = "status";
    11851226        $return_code = status(@ARGV);
     1227    } elsif (m/^check$/i) {
     1228        $command     = "check";
     1229        $return_code = check();
    11861230    } elsif (m/^permissions$/i) {
    11871231        $command = "permissions";
Note: See TracChangeset for help on using the changeset viewer.