and here is the html#!/usr/bin/perl -w use XML::Simple; use XML::Parser; if ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } else { $buffer = $ENV{'QUERY_STRING'}; } @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } my $newHost = $FORM{'host'}; my $newMet = $FORM{'metric'}; my $newRedSign = $FORM{'redSign'}; my $newRedVal = $FORM{'redVal'}; my $newRed = $newRedSign . " " . $newRedVal; my $newGreenSign = $FORM{'greenSign'}; my $newGreenVal = $FORM{'greenVal'}; my $newGreen = $newGreenSign . " " . $newGreenVal; $newHost = lc($newHost); my %hostMets; my $confHost; my $confMet; my $confRed; my $confGreen; my $hostcount = 0; my $metscount = 0; my $foundHost = 0; my $foundMet = 0; my $added = 0; sub readConfig { my ($xpat, $elem, %attrs) = @_; if($elem =~ /HOST/){ $confHost = $attrs{'NAME'}; if($confHost eq $newHost){ $foundHost = 1; } $hostMets{HOST}[$hostcount]{NAME} = $confHost; } elsif($elem =~ /METRIC/){ $confMet = $attrs{'NAME'}; $confRed = $attrs{'RED'}; $confGreen = $attrs{'GREEN'}; if(($confMet eq $newMet) && $foundHost){ $hostMets{HOST}[$hostcount]{METRIC}[$metscount]{NAM +E} = $confMet; $hostMets{HOST}[$hostcount]{METRIC}[$metscount]{RED +} = $newRed; $hostMets{HOST}[$hostcount]{METRIC}[$metscount]{GRE +EN} = $newGreen; $foundMet = 1; $added = 1; } else { $hostMets{HOST}[$hostcount]{METRIC}[$metscount]{NAM +E} = $confMet; $hostMets{HOST}[$hostcount]{METRIC}[$metscount]{RED +} = $confRed; $hostMets{HOST}[$hostcount]{METRIC}[$metscount]{GRE +EN} = $confGreen; } } } sub HandleEnd { my($xpat, $elem) = @_; if ($elem =~ /HOST/){ if($foundHost && !($foundMet)){ $hostMets{HOST}[$hostcount]{METRIC}[$metscount]{NAM +E} = $newMet; $hostMets{HOST}[$hostcount]{METRIC}[$metscount]{RED +} = $newRed; $hostMets{HOST}[$hostcount]{METRIC}[$metscount]{GRE +EN} = $newGreen; $foundMet = 1; $added = 1; } $hostcount++; $foundHost = 0; $metscount = 0; } elsif ($elem =~ /METRIC/){ $metscount++; } elsif ($elem =~ /opt/){ if(!($added)){ $hostMets{HOST}[$hostcount]{NAME} = $newHost; $hostMets{HOST}[$hostcount]{METRIC}[$metscount]{NAME} = $ne +wMet; $hostMets{HOST}[$hostcount]{METRIC}[$metscount]{RED} = $new +Red; $hostMets{HOST}[$hostcount]{METRIC}[$metscount]{GREEN} = $n +ewGreen; } } } sub HandleChar { } my $configFile = "ScoreProdMetsTest.xml"; my $configReader = new XML::Parser; $configReader->setHandlers ( Start => \&readConfig, End => \&HandleEnd, Char => \&HandleChar ); $configReader->parsefile( $configFile ); my $xsimple = XML::Simple->new(); my $xmlFormat = $xsimple->XMLout(\%hostMets, NoSort => 1, xmldecl => '<?xml version="1.0"?>'); open(FILE, ">outfile.xml"); print FILE $xmlFormat; close(FILE); print "Content-type: text/html\n\n"; print "<html>\n"; print "<head><title>METRIC ADDED</title></head>\n"; print "<body>\n"; print "Metric added</br>\n"; print "</body>\n"; print "</html>\n";
<html> <head><title>Config File Manipulator</title> <script language="Javascript" type="text/javascript" src="validFor +m.js"> </script> </head> <body> <center><h4>Add to Score Config File</h4></center> </br> <form id="MainForm" action="../cgi-bin/ib/xmlWriter.cgi" method="GET"> Enter the host name (example: scrpropbal800): <input id="host" type="text" name="host" class="reqd">* </br> Enter the name of the metric (Note: it must appear as it is reported b +y Ganglia): <input id="metric" type="text" name="metric" class="reqd">* </br> </br> The value is Red when <select id="redSign" name="redSign"> <option value=">" > > </option> <option value="<" > < </option> <option value="."> never </option> </select> <input id="redVal" type="text" name="redVal" > </br> </br> The value is Green when <select id="greenSign" name="greenSign"> <option value=">" > > </option> <option value="<" > < </option> <option value="@"> = </option> </select> <input id="greenVal" type="text" name="greenVal" class="reqd">* </br> <center><input type="submit" value="Add Metric"></center> </br> </br> * required field </form> </body> </html>
In reply to cgi help needed. by ub3rFrank
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |