Ben,

Did you also change the list_state code in the Mon::Client code? I see
where in the mon.cgi you check $scheduler_status[2] but I don't see
anywhere where you set that or get list_state to return that.

--Augie

On Tue, Mar 18, 2008 at 5:20 PM, Ben Ragg <[EMAIL PROTECTED]> wrote:
> Augie Schwer wrote:
>  > putting things into "disabled" and then forgetting all about them,
>  > which is dangerous and annoying.
>  >
>  > Care to share that code?
>  >
>  >
>  > The "hold" feature sounds pretty interesting. At my site I find people
>  Always happy to share :)
>
>  Version we're using is..."mon,v 1.22 2006/07/13 12:03:39 vitroth Exp $"
>  ...it's been run through perl tidy to clean it up a little, so the line
>  numbers won't match up (hence I won't even bother ;)
>
>  Attached our copy of the main mon program and mon.cgi
>
>
>  Changes to "mon"...
>
>  Under the global definitions, add a new array...
>
>  my @HOLD_ALERTS;       # dont send alerts, 0) end, 1) start, 2) by, 3)
>  reason
>
>
>  In the main monitoring loop "for ( ; ; ) {" near the top add a check for
>  an expired hold timer...
>
>  for ( ; ; ) {
>   debug( 1, "$i" . ( $STOPPED ? " (stopped)" : "" ) . "\n" );
>   $i++;
>   $tm = time;
>
>   # Check if the Hold Timer has ended
>   @HOLD_ALERTS = () if ( defined($HOLD_ALERTS[0]) && $HOLD_ALERTS[0] <
>  $tm );
>
>
>  In "sub doalert" add a bit on to the if ($STOPPED)
>
>   if ($STOPPED) {
>     syslog( "notice", "ignoring alert for $group,$service because the
>  mon scheduler is stopped" );
>     return;
>   } elsif (@HOLD_ALERTS) {
>     syslog( "notice",
>       "ignoring alert for $group,$service because alerts are held until
>  " . localtime( $HOLD_ALERTS[0] ) );
>     return;
>   }
>
>
>  In "sub client_command" add "hold" to the list of acceptable commands
>
>   if (
>     $l !~ /^(dump|login|disable|enable|quit|list|set|get|setview|getview|
>                     stop|start|loadstate|savestate|reset|clear|checkauth|
>
>  reload|term|test|servertime|ack|version|protid|hold)(\s+(.*))?$/ix
>     )
>   {
>     sock_write( $fh, "520 invalid command\n" );
>     return;
>   }
>
>
>  and also within sub client_command, define what the command hold
>  actually does...
>
>     #
>     # hold
>     #
>   } elsif ( $cmd eq "hold" ) {
>     my ( $period, $reason ) = split( /\s+/, $args, 2 );
>     $period = 180 if ( $period > 180 );
>     $HOLD_ALERTS[1] = time;
>     $HOLD_ALERTS[0] = $HOLD_ALERTS[1] + ( $period * 60 );
>     $HOLD_ALERTS[2] = $clients{$cl}->{"user"};
>     $HOLD_ALERTS[3] = $reason;
>     sock_write( $fh, "220 Alerts on hold until " . localtime(
>  $HOLD_ALERTS[0] ) . "\n" );
>
>  ...that should be all the changes in the mon file itself.
>
>
>
>  Also need to update the mon.cgi to make use of it...
>
>  Under "sub query_opstatus" add another scheduler_status...
>
>  if ( $scheduler_status[0] == 0 ) {
>   $webpage->print( "The scheduler on <b>$monhost:$monport</b> is
>  currently <font color=$greenlight_color>running</font>. ");
>  } elsif ( $scheduler_status[0] == 1 ) {
>   my $pretty_sched_down_time = strftime "%H:%M:%S %d-%b-%Y", localtime(
>  $scheduler_status[1] );
>   $webpage->print("<br>The scheduler has been <font
>  color=$redlight_color>stopped</font> since $pretty_sched_down_time.<br>\n");
>  } elsif ( $scheduler_status[0] == 2 ) {
>   my $pretty_sched_down_time = strftime "%H:%M:%S %d-%b-%Y", localtime(
>  $scheduler_status[1] );
>   my $pretty_sched_up_time = strftime "%H:%M:%S %d-%b-%Y", localtime(
>  $scheduler_status[4] );
>
>   $webpage->print("<br>The scheduler is running, but alerts have been
>  <font color=$yellowlight_color>held</font> since
>  $pretty_sched_down_time.<br>\n");
>   $webpage->print("Mon will return to normal operation at
>  $pretty_sched_up_time<br>");
>   $webpage->print("This hold was set by $scheduler_status[2] due to
>  \"$scheduler_status[3]\"<p>");
>  } else {    #value is undef, scheduler cannot be contacted (or auth failure)
>   $webpage->print("<br><font color=$redlight_color>The scheduler cannot
>  be contacted at this time.</font><br>\n");
>  }
>
>
>  And a new subroutine...
>
>  sub mon_hold {
>
>  my ($args) = @_;
>
>  my $retval;
>  my $conn = &mon_connect;
>  return 0 if $conn == 0;
>
>  $retval = $c->hold( $args, ${ackcomment} );
>
>  return $retval;
>  }
>
>  And under the "main programs" long list of elsif commands...
>
>  elsif ($command eq "mon_hold" ) {
>  &setup_page("Alerts Hold");
>  &mon_hold($args);
>  sleep 1;
>  &query_opstatus("summary");
>  }
>
>
>  And sub moncgi_custom_print_bar
>
>  my $fubar = <<EOF;
>  <tr>
>   <td colspan=3 align=center>
>     <form method="post" action="$url"
>  enctype="application/x-www-form-urlencoded">
>     <input name="command" value="mon_hold" type="hidden">
>     Hold alerts for <input name="args" size="2" type="text"> minutes,
>  reason:
>     <input name="ackcomment" size="20" type="text">
>     <input value="Hold" type="submit">
>     </form>
>   </td>
>   <td colspan=2  align=center>
>     <form method="post" action="$url"
>  enctype="application/x-www-form-urlencoded">
>     <input name="command" value="mon_hold" type="hidden">
>     <input name="args" value="0" type="hidden">
>     <input value="Remove Hold" type="submit">
>     </form>
>   </td>
>  </tr>
>
>  EOF
>
>     $webpage->print("$fubar");
>
>
>  Any questions feel free to sing out.
>
>  Cheers,
>  Ben
>
>
>



-- 
Augie Schwer - [EMAIL PROTECTED] - http://schwer.us
Key fingerprint = 9815 AE19 AFD1 1FE7 5DEE 2AC3 CB99 2784 27B0 C072

_______________________________________________
mon mailing list
mon@linux.kernel.org
http://linux.kernel.org/mailman/listinfo/mon

Reply via email to