/[mon-modules]/monshow.cgi
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /monshow.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by dpavlin, Sat Aug 10 16:33:09 2002 UTC revision 1.3 by dpavlin, Thu Oct 3 10:01:22 2002 UTC
# Line 3  Line 3 
3  # monshow - concise, user view-based opstatus summary  # monshow - concise, user view-based opstatus summary
4  #  #
5  # Jim Trocki, trockij@transmeta.com  # Jim Trocki, trockij@transmeta.com
6    #
7    # Midified to produce WAP (wml) output by
8    # Dobrica Pavlinusic <dpavlin@rot13.org>
9    # http://www.rot13.org/~dpavlin/sysadm.html
10    #
11    # Since it users <b>...</b> tags in wml outout, this script will NOT WORK
12    # on Nokia 7110.
13  #  #
14  # $Id$  # $Id$
15  #  #
# Line 82  GetOptions (\%opt, "showall", "auth", "h Line 89  GetOptions (\%opt, "showall", "auth", "h
89    
90  @ARGV == 0 || usage "No non-switch args expected\n";  @ARGV == 0 || usage "No non-switch args expected\n";
91    
92    my $WAP = 1;    # force wap output
93    
94  my $CGI;  my $CGI;
95  my %QUERY_ARGS;  my %QUERY_ARGS;
96  if (defined $ENV{"REQUEST_METHOD"})  if (defined $ENV{"REQUEST_METHOD"})
# Line 213  else Line 222  else
222    
223  compose_trailer;  compose_trailer;
224    
225  if ($CGI)  if ($WAP) {
226            print <<EOF;
227    Content-type: text/vnd.wap.wml
228    
229    $OUT_BUF
230    EOF
231    }
232    elsif ($CGI)
233  {  {
234      print <<EOF;      print <<EOF;
235  Content-type: text/html  Content-type: text/html
# Line 569  sub err_die Line 585  sub err_die
585  {  {
586      my $msg = shift;      my $msg = shift;
587    
588      if ($CGI)      if ($WAP) {
589    print <<EOF;
590    Content-type: text/vnd.wap.wml
591    
592    <?xml version="1.0"?>
593    <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
594    <wml>
595    <card id="error" title="Error">
596    <p>
597    $msg
598    </p>
599    </card>
600    </wml>
601    EOF
602        }
603        elsif ($CGI)
604      {      {
605  print <<EOF;  print <<EOF;
606  Content-type: text/html  Content-type: text/html
# Line 607  sub display_allok Line 638  sub display_allok
638  {  {
639      if ($CGI)      if ($CGI)
640      {      {
641          $OUT_BUF .= <<EOF;          $OUT_BUF .= <<EOF if (! $WAP);
642  <h2> All systems OK </h2>  <h2> All systems OK </h2>
643  <p>  <p>
644    
645  EOF  EOF
646            $OUT_BUF .= "<b> All systems OK </b>" if ($WAP);
647      }      }
648    
649      else      else
# Line 828  sub compose_header { Line 860  sub compose_header {
860      #      #
861      if ($CGI)      if ($CGI)
862      {      {
863          $OUT_BUF = <<EOF;          $OUT_BUF = <<EOF if (! $WAP);
864  <html>  <html>
865  <head>  <head>
866  <title> Operational Status </title>  <title> Operational Status </title>
867  EOF  EOF
868    
869            $OUT_BUF = <<EOF if ($WAP);
870    <?xml version="1.0"?>
871    <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
872    <wml>
873    EOF
874    
875          if ($CF->{"refresh"})          if ($CF->{"refresh"})
876          {          {
877              $OUT_BUF .= <<EOF;              $OUT_BUF .= <<EOF if (! $WAP);
878  <META HTTP-EQUIV="Pragma" CONTENT="no-cache">  <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
879  <META HTTP-EQUIV="Refresh" CONTENT=$CF->{refresh}>  <META HTTP-EQUIV="Refresh" CONTENT=$CF->{refresh}>
880  EOF  EOF
881          }          }
882    
883          $OUT_BUF .= <<EOF;          $OUT_BUF .= <<EOF if (! $WAP);
884  </head>  </head>
885  <body bgcolor="#$CF->{'bg'}">  <body bgcolor="#$CF->{'bg'}">
886  EOF  EOF
887    
888          if ($CF->{"html-header"} ne "")          if ($CF->{"html-header"} ne "")
889          {          {
890              $OUT_BUF .= $CF->{"html-header"};              $OUT_BUF .= $CF->{"html-header"} if (! $WAP);
891          }          }
892    
893          $OUT_BUF .= <<EOF;          $OUT_BUF .= <<EOF if (! $WAP);
894  <h1><FONT FACE="sans-serif">Operational Status</font></h1>  <h1><FONT FACE="sans-serif">Operational Status</font></h1>
895    
896  <table width="100%">  <table width="100%">
# Line 873  EOF Line 911  EOF
911                  </tr>                  </tr>
912  EOF  EOF
913    
914            # skip overview card if detail page is used or next page navigation
915            $OUT_BUF .= <<EOF if ($WAP && !$QUERY_ARGS{"detail"} && !$QUERY_ARGS{"p"});
916    <card id="status" title="Operational Status" ontimer="#display">
917     <timer value="10"/>
918    <p>
919    <b>Server:</b> $CF->{host}
920    <br/><b>Time:</b> $t
921    <br/><b>State:</b> $state
922    </p>
923    <p><a href="#display">Display status</a></p>
924    </card>
925    EOF
926    
927          if ($GLOBAL->{"view-name"} ne "")          if ($GLOBAL->{"view-name"} ne "")
928          {          {
929              $OUT_BUF .= <<EOF;              $OUT_BUF .= <<EOF if (! $WAP);
930                  <tr>                  <tr>
931                      <td align=right><b>View:</b></td>                      <td align=right><b>View:</b></td>
932                      <td><b>$GLOBAL->{"view-name"}</b></td>                      <td><b>$GLOBAL->{"view-name"}</b></td>
933                  </tr>                  </tr>
934  EOF  EOF
935                $OUT_BUF .= <<EOF if (! $WAP);
936    <b>View:</b> $GLOBAL->{"view-name"}
937    EOF
938          }          }
939    
940          $OUT_BUF .= <<EOF;          $OUT_BUF .= <<EOF if (! $WAP);
941              </table>              </table>
942          </td>          </td>
943    
# Line 908  EOF Line 962  EOF
962  <p>  <p>
963  <hr>  <hr>
964  EOF  EOF
965    
966      }      }
967    
968      else      else
# Line 1053  sub compose_table { Line 1108  sub compose_table {
1108      #      #
1109      if ($CGI)      if ($CGI)
1110      {      {
1111          $OUT_BUF .= <<EOF;          $OUT_BUF .= <<EOF if (! $WAP);
1112    
1113  <table cellpadding=2 cellspacing=1 bgcolor="#$CF->{'table-color'}" width="100%">  <table cellpadding=2 cellspacing=1 bgcolor="#$CF->{'table-color'}" width="100%">
1114      <tr>      <tr>
# Line 1071  sub compose_table { Line 1126  sub compose_table {
1126  EOF  EOF
1127      }      }
1128    
1129        my @wml;
1130    
1131      foreach my $l (@{$rows})      foreach my $l (@{$rows})
1132      {      {
1133          my ($depstate, $group, $service) = @{$l};          my ($depstate, $group, $service) = @{$l};
# Line 1171  EOF Line 1228  EOF
1228    
1229          else          else
1230          {          {
1231              if ($SUMMARY =~ /^[\s\n]*$/)              if (! $WAP)
1232              {              {
1233                  $SUMMARY = "<pre> </pre>";                  if ($SUMMARY =~ /^[\s\n]*$/)
1234              }                  {
1235                            $SUMMARY = "<pre> </pre>";
1236                    }
1237    
1238              else                  else
1239              {                  {
1240                  $SUMMARY = "<small>$SUMMARY</small>";                          $SUMMARY = "<small>$SUMMARY</small>";
1241              }                  }
1242    
1243              if ($bgcolor ne "")                  if ($bgcolor ne "")
1244              {                  {
1245                  $bgcolor = "bgcolor=\"#$bgcolor\"";                          $bgcolor = "bgcolor=\"#$bgcolor\"";
1246                    }
1247              }              }
1248              $OUT_BUF .= <<EOF;              $OUT_BUF .= <<EOF if (! $WAP);
1249    
1250  <tr $bgcolor>  <tr $bgcolor>
1251     <td> $DEP </td>     <td> $DEP </td>
# Line 1200  EOF Line 1260  EOF
1260  </tr>  </tr>
1261  EOF  EOF
1262    
1263                # dump just failuers to wap mobile
1264                if ($WAP) {
1265                    if ($sref->{"opstatus"} == $OPSTAT{"fail"}) {
1266                        push @wml,<<EOF;
1267    <p>
1268     <b>$GROUP
1269     <a href="$ENV{SCRIPT_NAME}?detail=$group,$service">$SERVICE</a></b>
1270     $TIME/$NEXT
1271     <b>$STATUS</b>
1272     $SUMMARY
1273    </p>
1274    EOF
1275                    } else {
1276                        push @wml,<<EOF;
1277    <p>
1278     $GROUP
1279     <a href="$ENV{SCRIPT_NAME}?detail=$group,$service">$SERVICE</a>
1280    </p>
1281    EOF
1282    
1283                    }
1284                }
1285    
1286          }          }
1287      }      }
1288    
1289      if ($CGI)      if ($CGI)
1290      {      {
1291          $OUT_BUF .= <<EOF;          $OUT_BUF .= <<EOF if (! $WAP);
1292  </table>  </table>
1293    
1294  EOF  EOF
1295            # generate page-by-page output
1296            my $on_page=10;
1297            my $max_page=int(($#wml + $on_page) / $on_page) - 1;
1298    
1299            if ($WAP) {
1300                    my $p = $QUERY_ARGS{"p"} || 1;  # current page
1301    
1302                    $OUT_BUF .= "<card id=\"display\" title=\"Monitoring $p/$max_page\">";
1303                    for (my $i = 0; $i < $on_page; $i++) {
1304                            $OUT_BUF .= $wml[$i + ($p-1) * $on_page];
1305                    }
1306                    # navigation
1307                    $OUT_BUF .= "<p>";
1308                    for (my $i = 1; $i <= $max_page; $i++) {
1309                            if ($i == $p) {
1310                                    $OUT_BUF .= "<b>$i</b> ";
1311                            } else {
1312                                    $OUT_BUF .= "<a href=\"$ENV{SCRIPT_NAME}?p=$i\">$i</a> ";
1313                            }
1314                    }
1315                    $OUT_BUF .= "</p>";
1316    
1317                    $OUT_BUF .= "</card>";
1318            }
1319      }      }
1320  }  }
1321    
# Line 1223  sub compose_disabled { Line 1330  sub compose_disabled {
1330          if ($CGI)          if ($CGI)
1331          {          {
1332              $OUT_BUF .= <<EOF;              $OUT_BUF .= <<EOF;
1333  <br>  <br/>
1334  Nothing is disabled.  Nothing is disabled.
 <p>  
1335  EOF  EOF
1336                $OUT_BUF .= "<p>" if (! $WAP);
1337          }          }
1338    
1339          else          else
# Line 1241  EOF Line 1348  EOF
1348      {      {
1349          if ($CGI)          if ($CGI)
1350          {          {
1351              $OUT_BUF .= <<EOF;              $OUT_BUF .= <<EOF if (! $WAP);
1352    
1353  <h2> Disabled Watches </h2>  <h2> Disabled Watches </h2>
1354    
1355  EOF  EOF
1356    
1357                $OUT_BUF .= "<b> Disabled Watches </b>" if ($WAP);
1358    
1359          }          }
1360    
1361          else          else
# Line 1257  EOF Line 1367  EOF
1367          {          {
1368              if ($CGI)              if ($CGI)
1369              {              {
1370                  $OUT_BUF .= "$watch <br>\n";                  $OUT_BUF .= "$watch <br/>\n";
1371              }              }
1372    
1373              else              else
# Line 1285  EOF Line 1395  EOF
1395  <h2> Disabled Services </h2>  <h2> Disabled Services </h2>
1396    
1397  EOF  EOF
1398    
1399                $OUT_BUF .= "<b> Disabled Services </b>" if ($WAP);
1400    
1401          }          }
1402    
1403          else          else
# Line 1295  EOF Line 1408  EOF
1408          {          {
1409              if ($CGI)              if ($CGI)
1410              {              {
1411                  $OUT_BUF .= "$_ <br>\n";                  $OUT_BUF .= "$_ <br/>\n";
1412              }              }
1413    
1414              else              else
# Line 1309  EOF Line 1422  EOF
1422      {      {
1423          if ($CGI)          if ($CGI)
1424          {          {
1425              $OUT_BUF .= <<EOF;              $OUT_BUF .= <<EOF if (! $WAP);
1426    
1427  <h2> Disabled Hosts </h2>  <h2> Disabled Hosts </h2>
1428    
1429  EOF  EOF
1430                $OUT_BUF .= <<EOF if ($WAP);
1431    
1432    <p><b> Disabled Hosts </b></p>
1433    
1434    EOF
1435          }          }
1436    
1437          else          else
# Line 1329  EOF Line 1447  EOF
1447              }              }
1448              if ($CGI)              if ($CGI)
1449              {              {
1450                  $OUT_BUF .= sprintf ("%-15s %s <br>\n", $group, "@HOSTS");                  $OUT_BUF .= sprintf ("%-15s %s <br/>\n", $group, "@HOSTS");
1451              }              }
1452    
1453              else              else
# Line 1344  EOF Line 1462  EOF
1462  sub compose_trailer {  sub compose_trailer {
1463      if ($CGI)      if ($CGI)
1464      {      {
1465          $OUT_BUF .= <<EOF;          $OUT_BUF .= <<EOF if (! $WAP);
1466  </body>  </body>
1467  </html>  </html>
1468  EOF  EOF
1469            $OUT_BUF .= <<EOF if ($WAP);
1470    </wml>
1471    EOF
1472      }      }
1473  }  }
1474    
# Line 1355  EOF Line 1476  EOF
1476  sub compose_detail {  sub compose_detail {
1477      my ($args, $st) = @_;      my ($args, $st) = @_;
1478    
1479      my ($group, $service) = split (/,/, $args, 2);      my ($group, $service, $optarg) = split (/,/, $args, 3);
1480    
1481      if (!defined ($st->{"opstatus"}->{$group}->{$service}))      if (!defined ($st->{"opstatus"}->{$group}->{$service}))
1482      {      {
# Line 1381  sub compose_detail { Line 1502  sub compose_detail {
1502    
1503      foreach my $k (qw (opstatus exitval last_check timer ack ackcomment))      foreach my $k (qw (opstatus exitval last_check timer ack ackcomment))
1504      {      {
1505          if ($CGI && $sref->{$k} =~ /^\s*$/)          if ($CGI && !$WAP && $sref->{$k} =~ /^\s*$/)
1506          {          {
1507              $d->{$k} = "<pre> </pre>";              $d->{$k} = "<pre> </pre>";
1508          }          }
# Line 1420  sub compose_detail { Line 1541  sub compose_detail {
1541          my $descr = pre_pad_if_empty ($st->{"desc"}->{$group}->{$service});          my $descr = pre_pad_if_empty ($st->{"desc"}->{$group}->{$service});
1542          my $hosts = pre_pad_if_empty ("@{$st->{groups}->{$group}}");          my $hosts = pre_pad_if_empty ("@{$st->{groups}->{$group}}");
1543    
1544          $OUT_BUF .= <<EOF;          $OUT_BUF .= <<EOF if (! $WAP);
1545    
1546  <h2><FONT FACE="sans-serif">Detail for $group/$service</font></h2>  <h2><FONT FACE="sans-serif">Detail for $group/$service</font></h2>
1547    
# Line 1439  $sref->{last_detail} Line 1560  $sref->{last_detail}
1560          </pre>          </pre>
1561  </table>  </table>
1562  EOF  EOF
1563                    my $wml = <<EOF;
1564    <p><b>Description:</b> $descr</p>
1565    <p><b>Summary:</b> $sum</p>
1566    <p><b>Hosts:</b> $hosts</p>
1567    <p><b>Detail: </b>
1568    EOF
1569                    my $wml_detail = "no detail -- bug!";
1570                    if ($WAP) {
1571                            if ($optarg eq "full") {
1572                                    $wml_detail = $sref->{last_detail};
1573                            } elsif (length $sref->{last_detail} > 200) {
1574                                    $wml .= substr($sref->{last_detail},0,200) . "... [<a href=\"$ENV{SCRIPT_NAME}?detail=$group,$service,full\">more</a>]";
1575                            } else {
1576                                    $wml .= $sref->{last_detail};
1577                            }
1578                    }
1579                    $wml .= "</p>";
1580    
1581          if ($d->{"ack"}) {          if ($d->{"ack"}) {
1582              my $comment = pre_pad_if_empty ($d->{"ackcomment"});              my $comment = pre_pad_if_empty ($d->{"ackcomment"});
1583    
1584              $OUT_BUF .= <<EOF;              $OUT_BUF .= <<EOF if (! $WAP);
1585  <table width="100%">  <table width="100%">
1586      <tr>      <tr>
1587          <td align=right width="15%"> <h2>Acknowledgment of failure</h2> </td>          <td align=right width="15%"> <h2>Acknowledgment of failure</h2> </td>
# Line 1452  EOF Line 1590  EOF
1590  </table>  </table>
1591    
1592  EOF  EOF
1593                $wml .= <<EOF if ($WAP);
1594    <p><b>Acknowledgment of failure</b>: $comment</p>
1595    EOF
1596          }          }
1597    
1598          $OUT_BUF .= <<EOF;          $OUT_BUF .= <<EOF if (! $WAP);
1599  <table cellpadding=2 cellspacing=1 bgcolor="#CCCCCC" width="100%">  <table cellpadding=2 cellspacing=1 bgcolor="#CCCCCC" width="100%">
1600  EOF  EOF
1601            $wml .= <<EOF if ($WAP);
1602    <p>
1603    EOF
1604    
1605          #          #
1606          # 0 = nothing special          # 0 = nothing special
# Line 1493  EOF Line 1637  EOF
1637              next if ($k->[2] == 1 && $$v == 0);              next if ($k->[2] == 1 && $$v == 0);
1638              next if ($k->[2] == 2 && $$v eq "");              next if ($k->[2] == 2 && $$v eq "");
1639    
1640              $OUT_BUF .= <<EOF;              $OUT_BUF .= <<EOF if (! $WAP);
1641      <tr>      <tr>
1642          <td align=right width="15%"><b>$k->[1]:</b></td>          <td align=right width="15%"><b>$k->[1]:</b></td>
1643          <td> $$v </td>          <td> $$v </td>
1644  EOF  EOF
1645                $wml .= "<br/><b>$k->[1]:</b> $$v" if ($WAP);
1646          }          }
1647    
1648          $OUT_BUF .= <<EOF;          $OUT_BUF .= <<EOF if (! $WAP);
1649  </table>  </table>
1650    EOF
1651            $wml .= <<EOF if ($WAP);
1652    </p>
1653  EOF  EOF
1654    
1655          #          #
# Line 1512  EOF Line 1659  EOF
1659          {          {
1660              if (defined ($CF->{"links"}->{$group}->{$service}->{"link-text"}))              if (defined ($CF->{"links"}->{$group}->{$service}->{"link-text"}))
1661              {              {
1662                  $OUT_BUF .= <<EOF;                  $OUT_BUF .= <<EOF if (! $WAP);
1663  <p>  <p>
1664  <h2><a href=\"$CF->{links}->{$group}->{$service}->{link}\">More Information</a></h2>  <h2><a href=\"$CF->{links}->{$group}->{$service}->{link}\">More Information</a></h2>
1665  $CF->{links}->{$group}->{$service}->{'link-text'}  $CF->{links}->{$group}->{$service}->{'link-text'}
1666    
1667  EOF  EOF
1668                    $wml .= <<EOF if ($WAP);
1669    <p>
1670    <b><a href=\"$CF->{links}->{$group}->{$service}->{link}\">More Information</a></b>
1671    $CF->{links}->{$group}->{$service}->{'link-text'}
1672    </p>
1673    EOF
1674              }              }
1675    
1676              else              else
1677              {              {
1678                  $OUT_BUF .= <<EOF;                  $OUT_BUF .= <<EOF if (! $WAP);
1679    <p>
1680    <a href="$CF->{links}->{$group}->{$service}->{link}">$CF->{links}->{$group}->{$service}->{link}</a>
1681    
1682    EOF
1683                    $wml .= <<EOF if ($WAP);
1684  <p>  <p>
1685  <a href="$CF->{links}->{$group}->{$service}->{link}">$CF->{links}->{$group}->{$service}->{link}</a>  <a href="$CF->{links}->{$group}->{$service}->{link}">$CF->{links}->{$group}->{$service}->{link}</a>
1686    </p>
1687    
1688  EOF  EOF
1689              }              }
1690          }          }
1691    
1692          $OUT_BUF .= <<EOF;          $OUT_BUF .= <<EOF if (! $WAP);
1693  <p>  <p>
1694  <a href="$ENV{SCRIPT_NAME}">Back to summary table</a>  <a href="$ENV{SCRIPT_NAME}">Back to summary table</a>
1695  <p>  <p>
1696    
1697  EOF  EOF
1698            # dump out wml
1699            if ($optarg eq "full") {
1700                    $wml_detail =~ s/[\n\r]+/<br\/>/g;
1701                    $wml = "<p>$wml_detail</p>";
1702            }
1703    
1704            $OUT_BUF .= <<EOF if ($WAP);
1705    <card id="display" title="Detail for $group/$service">
1706    $wml
1707    <do type="prev" label="Back to summary table"><prev/></do>
1708    </card>
1709    EOF
1710      }      }
1711    
1712      #      #
# Line 1649  sub pre_pad_if_empty Line 1820  sub pre_pad_if_empty
1820  {  {
1821      my $l = shift;      my $l = shift;
1822    
1823      return "<pre> </pre>" if ($l =~ /^\s*$/);      return "<pre> </pre>" if ($l =~ /^\s*$/ && !$WAP);
1824      $l;      $l;
1825  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.26