mirror of
https://github.com/munin-monitoring/contrib.git
synced 2018-11-08 00:59:34 +01:00
Added recursion to jenkins_
The previous behaviour ignored the folder structure in Jenkins 2.
This commit is contained in:
parent
1bba76b53b
commit
50e8e27722
1 changed files with 67 additions and 32 deletions
|
@ -54,6 +54,7 @@ use warnings;
|
||||||
use strict;
|
use strict;
|
||||||
use JSON;
|
use JSON;
|
||||||
use File::Basename;
|
use File::Basename;
|
||||||
|
use URI;
|
||||||
|
|
||||||
# VARS
|
# VARS
|
||||||
my $url = ($ENV{'url'} || 'localhost');
|
my $url = ($ENV{'url'} || 'localhost');
|
||||||
|
@ -79,7 +80,7 @@ my %states = (
|
||||||
'aborted'=>'failing',
|
'aborted'=>'failing',
|
||||||
'aborted_anime'=>'failing'
|
'aborted_anime'=>'failing'
|
||||||
);
|
);
|
||||||
my %counts = ('stable' => 0, 'unstable'=>0, 'failing'=>0, 'disabled'=>0);
|
my $auth = ( $user ne "" and $apiToken ne "" ? " --auth-no-challenge --user=$user --password=$apiToken" : "" );
|
||||||
|
|
||||||
if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
|
if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
|
||||||
if( $type eq "results" ) {
|
if( $type eq "results" ) {
|
||||||
|
@ -127,37 +128,20 @@ if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
# CODE
|
|
||||||
my $auth = ( $user ne "" and $apiToken ne "" ? " --auth-no-challenge --user=$user --password=$apiToken" : "" );
|
|
||||||
my $cmd = "$wgetBin $auth -qO- $url:$port$context";
|
my $cmd = "$wgetBin $auth -qO- $url:$port$context";
|
||||||
|
|
||||||
if( $type eq "results" ) {
|
if( $type eq "results" ) {
|
||||||
my $result = `$cmd/api/json`;
|
my $counts = get_results('');
|
||||||
my $parsed = decode_json($result);
|
|
||||||
foreach my $cur(@{$parsed->{'jobs'}}) {
|
|
||||||
if (defined $states{$cur->{'color'}}) {
|
|
||||||
$counts{$states{$cur->{'color'}}} += 1;
|
|
||||||
} else {
|
|
||||||
warn "Ignoring unknown color " . $cur->{'color'} . "\n"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach my $status (keys %counts) {
|
foreach my $status (keys %{$counts}) {
|
||||||
print "build_$status.value $counts{$status}\n";
|
print "build_$status.value $counts->{$status}\n";
|
||||||
}
|
}
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $type eq "running" ) {
|
if( $type eq "running" ) {
|
||||||
my $count = 0;
|
my $running_count = get_running('');
|
||||||
my $result = `$cmd/api/json`;
|
print "build_running.value ", $running_count, "\n";
|
||||||
my $parsed = decode_json($result);
|
|
||||||
foreach my $cur(@{$parsed->{'jobs'}}) {
|
|
||||||
if( $cur->{'color'} =~ /anime$/ ) {
|
|
||||||
$count += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
print "build_running.value ", $count, "\n";
|
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,3 +152,54 @@ if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
my %counts;
|
||||||
|
|
||||||
|
sub get_results{
|
||||||
|
my $query_context = shift;
|
||||||
|
die "get_results requires an argument" unless defined $query_context;
|
||||||
|
unless (%counts) {
|
||||||
|
# initialise
|
||||||
|
%counts = ('stable' => 0, 'unstable'=>0, 'failing'=>0, 'disabled'=>0);
|
||||||
|
}
|
||||||
|
my $cmd = "$wgetBin $auth -qO- $url:$port$context$query_context/api/json";
|
||||||
|
my $result = `$cmd`;
|
||||||
|
my $parsed = decode_json($result);
|
||||||
|
foreach my $cur(@{$parsed->{'jobs'}}) {
|
||||||
|
if (exists $cur->{'color'} && defined $states{$cur->{'color'}}) {
|
||||||
|
$counts{$states{$cur->{'color'}}} += 1;
|
||||||
|
} elsif ($cur->{'_class'} eq 'com.cloudbees.hudson.plugins.folder.Folder'){
|
||||||
|
my $uri = URI->new($cur->{'url'});
|
||||||
|
my $folder = $uri->path;
|
||||||
|
get_results($folder);
|
||||||
|
} else {
|
||||||
|
warn "Ignoring unknown color " . $cur->{'color'} . "\n"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return \%counts;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
my $running_count;
|
||||||
|
sub get_running{
|
||||||
|
my $query_context = shift;
|
||||||
|
die "get_results requires an argument" unless defined $query_context;
|
||||||
|
$running_count //= 0;
|
||||||
|
my $cmd = "$wgetBin $auth -qO- $url:$port$context$query_context/api/json";
|
||||||
|
my $result = `$cmd`;
|
||||||
|
my $parsed = decode_json($result);
|
||||||
|
foreach my $cur(@{$parsed->{'jobs'}}) {
|
||||||
|
if( exists $cur->{'color'} && $cur->{'color'} =~ /anime$/ ) {
|
||||||
|
$running_count += 1;
|
||||||
|
} elsif ($cur->{'_class'} eq 'com.cloudbees.hudson.plugins.folder.Folder'){
|
||||||
|
my $uri = URI->new($cur->{'url'});
|
||||||
|
my $folder = $uri->path;
|
||||||
|
get_running($folder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $running_count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue