in reply to Re: perl cpu usage on windows machines
in thread perl cpu usage on windows machines
#!/usr/bin/perl use strict; use Warnings; use HTTP::Status; use HTTP::Response; use HTTP::Request; use LWP::UserAgent; if (@ARGV < 2) { print "USAGE: IsPageAvailable [-r] <MonitorName> <URL> <Hosts file +> [Http::Host]\n"; } else { # Treat the -r option, in wich case the screap will search in the +response returned to SUCCEED # string and treat the returned monitor accoringly. my $checkResponse = 0; if ($ARGV[0] eq "-r") { $checkResponse = 1; shift @ARGV; } my ($strMonitorName, $strURL, $hosts, $httpHost) = @ARGV; # Use the configuration file only if specefied. if (defined($hosts)) { # Generate the computerName and domainName variables used late +r to search in the hosts file my $computerName = lc($ENV{'COMPUTERNAME'}); $strURL =~ /^http.*\/\/(.+?)[\:\/]/; my $domainName = $1; my $ip; # Convert the domain using the hosts file supplied open (HOSTS, '<', $hosts) or die "Cant open configuration file + $hosts\n"; END: while (my $line = <HOSTS>) { if ($line =~ /$computerName:$domainName:(.+)/) { $ip = $1; chomp($ip); last END; } } close(HOSTS); # No entries in the hosts found die "No entries in $hosts file found for this machine ($comput +erName, $domainName)\n" if (!defined($ip)); # Substitute in the URL to the found $ip $strURL =~ s/$domainName/$ip/; } # Perform the GET command print "Performing GET on $strURL\n"; my $ua = LWP::UserAgent->new; $ua->timeout(15); # We can define the httpHost my $request; if (defined($httpHost)) { $request = HTTP::Request->new(GET => $strURL, HTTP::Headers->n +ew(Host => $httpHost)); } else { $request = HTTP::Request->new(GET => $strURL); } my $response = $ua->request($request); my $nCode = $response->code; my $nMonitorValue; my $nReturnCode = $response->code; print "Return Code = $nReturnCode\n"; # Check the returned code and format the opcmon command if ($nReturnCode == 200) { if ($checkResponse) { if ($response->content =~ /SUCCEEDED/m) { $nMonitorValue = 0; } else { $nMonitorValue = 1; } } else { $nMonitorValue = 0; } } else { $nMonitorValue = 1; } # Send the opcmon print "opcmon value = $nMonitorValue\n"; my $strCmd ="opcmon $strMonitorName=$nMonitorValue"; my $exit = system($strCmd); exit $exit; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: perl cpu usage on windows machines
by CountZero (Bishop) on Jul 14, 2008 at 14:57 UTC | |
by leonidlm (Pilgrim) on Jul 14, 2008 at 15:09 UTC | |
|
Re^3: perl cpu usage on windows machines
by GrandFather (Saint) on Jul 14, 2008 at 22:05 UTC |