Subversion Repositories sysadmin_scripts

Rev

Rev 90 | Rev 92 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 90 Rev 91
Line 104... Line 104...
104
   } elsif ( $parameters->{'type'} eq 'ping' ) {
104
   } elsif ( $parameters->{'type'} eq 'ping' ) {
105
      $result = checkPing( $parameters->{'url'}, $parameters->{'timeout'} );
105
      $result = checkPing( $parameters->{'url'}, $parameters->{'timeout'} );
106
   } elsif ( $parameters->{'type'} eq 'netcat' ) {
106
   } elsif ( $parameters->{'type'} eq 'netcat' ) {
107
      $result = checkNetCat( $parameters->{'url'}, $parameters->{'port'}, $parameters->{'timeout'} );
107
      $result = checkNetCat( $parameters->{'url'}, $parameters->{'port'}, $parameters->{'timeout'} );
108
   } else {
108
   } else {
-
 
109
      warn "Unknown test type $parameters->{type}, aborting test\n";
109
      $result = 0;
110
      $result = 0;
110
   }
111
   }
111
   return $result;
112
   return $result;
112
}
113
}
113
 
114
 
Line 116... Line 117...
116
sub flagFileName {
117
sub flagFileName {
117
   my $name = shift;
118
   my $name = shift;
118
   return "/tmp/$name.down";
119
   return "/tmp/$name.down";
119
}
120
}
120
 
121
 
-
 
122
# Report outage via system mail
-
 
123
# your system must be able to send e-mail from 'report from'
-
 
124
# otherwise, you'll need to use something like sendemail.pl
-
 
125
sub reportViaMail {
-
 
126
   my ( $name,$parameters ) = @_;
-
 
127
   use Email::MIME;
-
 
128
   my $message = Email::MIME->create(
-
 
129
     header_str => [
-
 
130
       From    => $parameters->{'report from'},
-
 
131
       To      => $parameters->{'report to'},
-
 
132
       Subject => "Outage on $name",
-
 
133
     ],
-
 
134
     attributes => {
-
 
135
       encoding => 'quoted-printable',
-
 
136
       charset  => 'ISO-8859-1',
-
 
137
     },
-
 
138
     body_str => "$name has been reported as current state down\n",
-
 
139
   );
-
 
140
 
-
 
141
   # send the message
-
 
142
   use Email::Sender::Simple qw(sendmail);
-
 
143
   sendmail($message);   
-
 
144
}   
-
 
145
 
121
# report the outage
146
# report the outage
122
sub reportOutage {
147
sub reportOutage {
123
   my ( $name,$parameters ) = @_;
148
   my ( $name,$parameters ) = @_;
-
 
149
   if ( $parameters->{'report type'} eq 'mail' ) {
124
   # do something really nice here
150
      &reportViaMail( $name,$parameters );
-
 
151
   } else {
-
 
152
      warn "Do not have a way of notifying outage for $name\n";
-
 
153
   }
125
}
154
}
126
 
155
 
127
# this will put a flag file in /tmp/monitorNetwork which will control
156
# this will put a flag file in /tmp/monitorNetwork which will control
128
# countdown in case of failure
157
# countdown in case of failure
129
# if the countdown is exceeded, it will report the status 
158
# if the countdown is exceeded, it will report the status