Chinaunix首页 | 论坛 | 博客
  • 博客访问: 486904
  • 博文数量: 173
  • 博客积分: 4112
  • 博客等级: 上校
  • 技术积分: 1577
  • 用 户 组: 普通用户
  • 注册时间: 2010-02-26 10:12
文章分类

全部博文(173)

文章存档

2012年(1)

2010年(172)

我的朋友

分类:

2010-02-26 10:49:37

#!/usr/bin/perl -w
#
# check_squid - Nagios check plugin for testing a Squid proxy
use LWP::UserAgent;
use HTTP::Request::Common qw(POST GET);
use HTTP::Headers;
use strict;
my ($url, $urluser, $urlpass, $proxy, $proxyport,
        $proxyuser, $proxypass, $expectstatus) = @ARGV;
unless ($url && $proxy && $expectstatus)
{
        print "Usage: url urluser urlpass proxy proxyport proxyuser proxypass expectstatus\n";
        print " url       -> The URL to check on the internet (";
        print " urluser   -> Username if the web site required authentication (- = none)\n";
        print " urlpass   -> Password if the web site required authentication (- = none)\n";
        print " proxy     -> Server that squid runs on (proxy.mydomain)\n";
        print " proxyport -> TCP port that Squid listens on (3128)\n";
        print " proxyuser -> Username if the web site required authentication (- = none)\n";
        print " proxypass -> Password if the web site required authentication (- = none)\n";
        print " expectstatus -> HTTP code that should be returned\n";
        print "                  (2 = anything that begins with 2)\n";
        exit -1;
}
$urluser='' if $urluser eq '-';
$urlpass='' if $urlpass eq '-';
$proxyuser='' if $proxyuser eq '-';
$proxypass='' if $proxypass eq '-';
my $ua = new LWP::UserAgent;
$ua->parse_head(0);
my $h = HTTP::Headers->new();
if ($proxy)
{
        $ua->proxy(['http', 'ftp'], "");
        if ($proxyuser)
        {
                $h->proxy_authorization_basic($proxyuser,$proxypass);
        }
}
if ($urluser)
{
        $h->authorization_basic($urluser, $urlpass);
}
my $req = HTTP::Request->new('GET', $url, $h);
my $res = $ua->request($req);
if ($res->status_line =~ /^$expectstatus/)
{
        print "OK - Status: ".$res->status_line."\n";
        exit 0;
}
else
{
        print "WARNING - Status: ".$res->status_line." (but expected $expectstatus...)\n";
        exit 1;
}
阅读(519) | 评论(0) | 转发(0) |
0

上一篇:squid原理

下一篇:check_squid命令参数

给主人留下些什么吧!~~