Sorry forgot about that, it's been so long since I touched any of this :)

955c955
<       return (1, $l);
---
>       return (0, $l);
957c957,960
<       return (0, $1);
---
>       return (1, $1);
>     } elsif ($l =~ /alerts held by (\S*) from (\d+) to (\d+) comment
(.*)$/) {
>         my $comment = _un_esc_str ($4);
>         return (2, $2, $1, $comment, $3);
1342a1346,1371
>     return $r;
> }
>
> sub hold {
>     my $self = shift;
>     my ($time, $comment) = @_;
>
>     undef $self->{"ERROR"};
>
>     if (!$self->{"CONNECTED"}) {
>         $self->{"ERROR"} = "not connected";
>         return undef;
>     }
>
>     $comment = _esc_str ($comment, 1);
>
>     my ($r, $l) = _do_cmd ($self->{"HANDLE"}, "hold $time $comment");
>
>     if (!defined $r) {
>         $self->{"ERROR"} = $l;
>         return undef;
>     } elsif ($r !~ /^220/) {
>         $self->{"ERROR"} = $r;
>         return undef;
>     }
>

>From memory I had to flip the scheduler states around because Mon::Client
at the time was different to what Mon was actually doing. If you want me
to send the full copy of MON/Client.pm, just sing out. I don't think I ran
perltidy over Client.pm, so line numbers should be correct.

Version is listed as
# $Id: Client.pm,v 1.3 2006/09/05 17:09:21 vitroth Exp $

Cheers,
Ben

Ben Ragg - Internode - Network Operations
150 Grenfell Street, Adelaide, SA, 5000
Phone: 13NODE Web: http://www.on.net

On Fri, 21 Mar 2008, Augie Schwer wrote:

> 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