Index: monshow.cgi =================================================================== RCS file: /home/dpavlin/private/cvsroot/mon-modules/monshow.cgi,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -r1.1 -r1.2 --- monshow.cgi 10 Aug 2002 16:33:09 -0000 1.1 +++ monshow.cgi 10 Aug 2002 16:44:38 -0000 1.2 @@ -4,6 +4,13 @@ # # Jim Trocki, trockij@transmeta.com # +# Midified to produce WAP (wml) output by +# Dobrica Pavlinusic +# http://www.rot13.org/~dpavlin/sysadm.html +# +# Since it users ... tags in wml outout, this script will NOT WORK +# on Nokia 7110. +# # $Id: monshow 1.7 Sun, 24 Jun 2001 22:41:40 -0400 trockij $ # # Copyright (C) 1998, Jim Trocki @@ -82,6 +89,8 @@ @ARGV == 0 || usage "No non-switch args expected\n"; +my $WAP = 1; # force wap output + my $CGI; my %QUERY_ARGS; if (defined $ENV{"REQUEST_METHOD"}) @@ -213,7 +222,14 @@ compose_trailer; -if ($CGI) +if ($WAP) { + print < + + + +

+$msg +

+
+
+EOF + } + elsif ($CGI) { print < All systems OK

EOF + $OUT_BUF .= " All systems OK " if ($WAP); } else @@ -828,31 +860,37 @@ # if ($CGI) { - $OUT_BUF = < Operational Status EOF + $OUT_BUF = < + + +EOF + if ($CF->{"refresh"}) { - $OUT_BUF .= < {refresh}> EOF } - $OUT_BUF .= < EOF if ($CF->{"html-header"} ne "") { - $OUT_BUF .= $CF->{"html-header"}; + $OUT_BUF .= $CF->{"html-header"} if (! $WAP); } - $OUT_BUF .= <Operational Status @@ -873,17 +911,33 @@ EOF + # skip overview card if detail page is used or next page navigation + $OUT_BUF .= < + +

+Server: $CF->{host} +
Time: $t +
State: $state +

+

Display status

+ +EOF + if ($GLOBAL->{"view-name"} ne "") { - $OUT_BUF .= <
EOF + $OUT_BUF .= <View: $GLOBAL->{"view-name"} +EOF } - $OUT_BUF .= < @@ -908,6 +962,7 @@


EOF + } else @@ -1053,7 +1108,7 @@ # if ($CGI) { - $OUT_BUF .= <
@@ -1071,6 +1126,8 @@ EOF } + my @wml; + foreach my $l (@{$rows}) { my ($depstate, $group, $service) = @{$l}; @@ -1171,6 +1228,8 @@ else { + if (! $WAP) + { if ($SUMMARY =~ /^[\s\n]*$/) { $SUMMARY = "
 
"; @@ -1185,7 +1244,8 @@ { $bgcolor = "bgcolor=\"#$bgcolor\""; } - $OUT_BUF .= < @@ -1200,15 +1260,62 @@ EOF + # dump just failuers to wap mobile + if ($WAP) { + if ($sref->{"opstatus"} == $OPSTAT{"fail"}) { + push @wml,< + $GROUP + $SERVICE + $TIME/$NEXT + $STATUS + $SUMMARY +

+EOF + } else { + push @wml,< + $GROUP + $SERVICE +

+EOF + + } + } + } } if ($CGI) { - $OUT_BUF .= < EOF + # generate page-by-page output + my $on_page=10; + my $max_page=int(($#wml + $on_page -1) / $on_page); + + if ($WAP) { + my $p = $QUERY_ARGS{"p"} || 1; # current page + + $OUT_BUF .= ""; + for (my $i = 0; $i < $on_page; $i++) { + $OUT_BUF .= $wml[$i + ($p-1) * $on_page]; + } + # navigation + $OUT_BUF .= "

"; + for (my $i = 1; $i < $max_page; $i++) { + if ($i == $p) { + $OUT_BUF .= "$i "; + } else { + $OUT_BUF .= "$i "; + } + } + $OUT_BUF .= "

"; + + $OUT_BUF .= "
"; + } } } @@ -1223,10 +1330,10 @@ if ($CGI) { $OUT_BUF .= < +
Nothing is disabled. -

EOF + $OUT_BUF .= "

" if (! $WAP); } else @@ -1241,11 +1348,14 @@ { if ($CGI) { - $OUT_BUF .= < Disabled Watches EOF + + $OUT_BUF .= " Disabled Watches " if ($WAP); + } else @@ -1257,7 +1367,7 @@ { if ($CGI) { - $OUT_BUF .= "$watch
\n"; + $OUT_BUF .= "$watch
\n"; } else @@ -1285,6 +1395,9 @@

Disabled Services

EOF + + $OUT_BUF .= " Disabled Services " if ($WAP); + } else @@ -1295,7 +1408,7 @@ { if ($CGI) { - $OUT_BUF .= "$_
\n"; + $OUT_BUF .= "$_
\n"; } else @@ -1309,11 +1422,16 @@ { if ($CGI) { - $OUT_BUF .= < Disabled Hosts EOF + $OUT_BUF .= < Disabled Hosts

+ +EOF } else @@ -1329,7 +1447,7 @@ } if ($CGI) { - $OUT_BUF .= sprintf ("%-15s %s
\n", $group, "@HOSTS"); + $OUT_BUF .= sprintf ("%-15s %s
\n", $group, "@HOSTS"); } else @@ -1344,10 +1462,13 @@ sub compose_trailer { if ($CGI) { - $OUT_BUF .= < EOF + $OUT_BUF .= < +EOF } } @@ -1355,7 +1476,7 @@ sub compose_detail { my ($args, $st) = @_; - my ($group, $service) = split (/,/, $args, 2); + my ($group, $service, $optarg) = split (/,/, $args, 3); if (!defined ($st->{"opstatus"}->{$group}->{$service})) { @@ -1381,7 +1502,7 @@ foreach my $k (qw (opstatus exitval last_check timer ack ackcomment)) { - if ($CGI && $sref->{$k} =~ /^\s*$/) + if ($CGI && !$WAP && $sref->{$k} =~ /^\s*$/) { $d->{$k} = "
 
"; } @@ -1420,7 +1541,7 @@ my $descr = pre_pad_if_empty ($st->{"desc"}->{$group}->{$service}); my $hosts = pre_pad_if_empty ("@{$st->{groups}->{$group}}"); - $OUT_BUF .= <Detail for $group/$service @@ -1439,11 +1560,28 @@
View: $GLOBAL->{"view-name"}
$DEP
EOF + my $wml = <Description: $descr

+

Summary: $sum

+

Hosts: $hosts

+

Detail: +EOF + my $wml_detail = "no detail -- bug!"; + if ($WAP) { + if ($optarg eq "full") { + $wml_detail = $sref->{last_detail}; + } elsif (length $sref->{last_detail} > 200) { + $wml .= substr($sref->{last_detail},0,200) . "... [more]"; + } else { + $wml .= $sref->{last_detail}; + } + } + $wml .= "

"; if ($d->{"ack"}) { my $comment = pre_pad_if_empty ($d->{"ackcomment"}); - $OUT_BUF .= <

Acknowledgment of failure

@@ -1452,11 +1590,17 @@ EOF + $wml .= <Acknowledgment of failure: $comment

+EOF } - $OUT_BUF .= < EOF + $wml .= < +EOF # # 0 = nothing special @@ -1493,16 +1637,19 @@ next if ($k->[2] == 1 && $$v == 0); next if ($k->[2] == 2 && $$v eq ""); - $OUT_BUF .= < $k->[1]: $$v EOF + $wml .= "
$k->[1]: $$v" if ($WAP); } - $OUT_BUF .= < - +EOF + $wml .= < EOF # @@ -1512,30 +1659,54 @@ { if (defined ($CF->{"links"}->{$group}->{$service}->{"link-text"})) { - $OUT_BUF .= <

{links}->{$group}->{$service}->{link}\">More Information

$CF->{links}->{$group}->{$service}->{'link-text'} EOF + $wml .= < +{links}->{$group}->{$service}->{link}\">More Information +$CF->{links}->{$group}->{$service}->{'link-text'} +

+EOF } else { - $OUT_BUF .= < +$CF->{links}->{$group}->{$service}->{link} + +EOF + $wml .= < $CF->{links}->{$group}->{$service}->{link} +

EOF } } - $OUT_BUF .= < Back to summary table

EOF + # dump out wml + if ($optarg eq "full") { + $wml_detail =~ s/[\n\r]+//g; + $wml = "

$wml_detail

"; + } + + $OUT_BUF .= < +$wml + + +EOF } # @@ -1649,6 +1820,6 @@ { my $l = shift; - return "
 
" if ($l =~ /^\s*$/); + return "
 
" if ($l =~ /^\s*$/ && !$WAP); $l; }