- 論壇徽章:
- 0
|
zhlong8 發(fā)表于 2012-04-12 10:21 ![]()
這個(gè)模塊不是 Perl 自帶的嗎,安裝它干嘛
好吧我離線安裝成功了。。!,F(xiàn)在遇到了新的問(wèn)題,其實(shí)我的目的是想用Solarwinds來(lái)監(jiān)控apache的服務(wù)狀態(tài),現(xiàn)在依然是報(bào)錯(cuò),幫我看一下這個(gè)腳本有需要修改的地方么?- #!/usr/bin/perl
- #
- #
- # Copyright ¿ 1999-2008 SolarWinds, Inc. All Rights Reserved.
- #
- #
- use LWP::UserAgent;
- if (@ARGV[0] =~ /\bhelp\b/)
- {
- print "ServerUptime.pl StatusURL\n";
- print "StatusURL - url to apache server status (ex. www.mysite.com/server-status ) \n";
- exit 1;
- }
- # Get hostname and trim newline
- $localhost = `hostname`;
- $localhost =~ s/\s*$//g;
- $hostname = shift || "localhost"; # $localhost
- $url = "$hostname/server-status?auto&match=www&errors=0";
- # Create a user agent object
- $ua = new LWP::UserAgent;
- $ua->agent("AgentName/0.1 " . $ua->agent);
- # Create a request
- my $req = new HTTP::Request GET => "http://$url";
- #print "http://$url\n";
- $req->content_type("application\/x-www-form-urlencoded");
- $req->content("match=www&errors=0");
- # Pass request to the user agent and get a response back
- my $res = $ua->request($req);
- my $val ="";
- # Check the outcome of the response
- if ($res->is_success) {
- #print $res->content;
- $content = $res->content;
- while ( $content =~ /Uptime:\s(\d+)/ig){
- $hour = sprintf("%d",$1 / 3600);
- $min = sprintf("%d",($1-$hour*3600)/60);
- $sec = sprintf("%d",($1-$hour*3600-$min*60));
- $sut = "${hour}h ${min}m ${sec}s";
- print "Message: Server Uptime at host \"$hostname\" $sut\n";
- print "statistic: $1\n";
- exit 0;
- }
- } else {
- print "Message: unable access to $hostname\n";
- print "Statistic: 0\n";
- exit 1;
- }
復(fù)制代碼 |
|