使用nagios GUI监控jenkins的工作状况 [英] Monitor jenkins jobs health using nagios GUI
问题描述
我正在使用check_http
插件来发现jenkins服务(Winstone托管和Apache托管)在安装check_mk_agent
的主机上是否正在运行.并使用以下命令在作为nagios GUI的单个ui上对其进行了监视.
I am using check_http
plugin for discovering jenkins service(Winstone hosted and Apache hosted) is running or not on hosts on which check_mk_agent
is installed. And its been monitored on single ui that is nagios GUI, using following command.
./check_http -H Host_Name -u /api/xml?depth=0 -p 8080
下一步是使用jenkins REST api
解析特定jenkins主服务器上的作业,并在nagios GUI
中监视每个作业的运行状况.
Next step is to parse the jobs on specific jenkins master server using jenkins REST api
and monitor each job's health in nagios GUI
.
有人可以告诉我任何想法,以便我可以在单个GUI上监视jenkins作业.任何脚本或插件都值得赞赏.
Could someone please give me any idea on this so that I can monitor the jenkins jobs on single GUI. Any script or plugin much appreciated.
推荐答案
#!/usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent;
use XML::Twig;
use HTTP::Request;
use Getopt::Long;
use Nagios::Plugin;
#use File::stat;
use File::Basename;
my $PROGNAME = basename($0);
my $p = Nagios::Plugin->new(
usage => "Usage: %s [ -H|--host ] [ -p|--port ]",
extra => "
Examples:
$PROGNAME --host myhost -port 8080
Check Host name and port.
");
$p->add_arg(
spec => 'host|f=s',
required => 1,
help => "-H, --host=Hostname. REQUIRED.");
$p->add_arg(
spec => 'port|a=i',
default => 8080,
help => "-p, --port=Portnumber. Default 8080.");
$p->getopts;
my $o_host = $p->opts->host ;
my $o_port = $p->opts->port;
my $protocol = 'http';
my $o_url = '/api/xml';
my @jobs;
my $url = $protocol . "://" . $o_host . ":" . $o_port . $o_url ;
#print $url,"\n";
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
my $response = $ua->get($url);
if ($response->is_success) {
my $content = $response->decoded_content; # or whatever
XML::Twig->new( twig_roots => { 'job/name' => sub { push @jobs, $_->text; } }) ->parseurl( $url);
}
else {
$p->nagios_die( CRITICAL, "Bad page found" );
}
#print @jobs;
foreach my $job_name (@jobs) {
#print $job_name;
my $job_url = $protocol . "://" . $o_host . ":" . $o_port . "/" . "job" . "/" . $job_name . $o_url ;
#print $job_url;
my $response2 = $ua->get($job_url);
#print $job_url;
if ($response2->is_success) {
$p->nagios_die( OK, "Job link valid" );
}
else {
$p->nagios_die( CRITICAL, "Bad page found" );
}
}
这篇关于使用nagios GUI监控jenkins的工作状况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!