2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00

Merge pull request #883 from henti/master

Folder recursion and offline fix for jenkins plugin
This commit is contained in:
sumpfralle 2018-03-08 02:17:18 +01:00 committed by GitHub
commit 36c0717b95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 76 additions and 41 deletions

View File

@ -54,6 +54,7 @@ use warnings;
use strict;
use JSON;
use File::Basename;
use URI;
# VARS
my $url = ($ENV{'url'} || 'localhost');
@ -79,7 +80,7 @@ my %states = (
'aborted'=>'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( $type eq "results" ) {
@ -103,7 +104,7 @@ if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
print "build_stable.draw STACK\n";
print "build_stable.label stable\n";
print "build_stable.type GAUGE\n";
print "build_stable.colour 294D99\n";
print "build_stable.colour 294D99\n";
exit;
}
if( $type eq "queue" ) {
@ -125,46 +126,80 @@ if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
print "build_running.label running Builds\n";
print "build_running.type GAUGE\n";
exit;
}
}
} 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" ) {
my $result = `$cmd/api/json`;
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) {
print "build_$status.value $counts{$status}\n";
my $counts = get_results('');
foreach my $status (keys %{$counts}) {
print "build_$status.value $counts->{$status}\n";
}
exit;
}
if( $type eq "running" ) {
my $count = 0;
my $result = `$cmd/api/json`;
my $parsed = decode_json($result);
foreach my $cur(@{$parsed->{'jobs'}}) {
if( $cur->{'color'} =~ /anime$/ ) {
$count += 1;
}
}
print "build_running.value ", $count, "\n";
exit;
my $running_count = get_running('');
print "build_running.value ", $running_count, "\n";
exit;
}
if( $type eq "queue" ) {
my $result = `$cmd/queue/api/json`;
my $parsed = decode_json($result);
my $parsed = decode_json($result);
print "build_count.value ", scalar( @{$parsed->{'items'}} ), "\n";
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;
}
}

18
plugins/jenkins/jenkins_nodes_ Normal file → Executable file
View File

@ -51,7 +51,7 @@ if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
my $result = `$cmd/computer/api/json`;
my $parsed = decode_json($result);
foreach my $cur(@{$parsed->{'computer'}}) {
if( $cur->{'offline'} =~ /false$/ ) {
if( !$cur->{'offline'} ) {
my $cat = $cur->{'displayName'};
$cat =~ s/\./\_/g;
if( $lcount > 0 ){
@ -77,7 +77,7 @@ if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
my $result = `$cmd/computer/api/json`;
my $parsed = decode_json($result);
foreach my $cur(@{$parsed->{'computer'}}) {
if( $cur->{'offline'} =~ /false$/ ) {
if( !$cur->{'offline'} ) {
my $cat = $cur->{'displayName'};
$cat =~ s/\./\_/g;
if( $lcount > 0 ){
@ -103,7 +103,7 @@ if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
my $result = `$cmd/computer/api/json`;
my $parsed = decode_json($result);
foreach my $cur(@{$parsed->{'computer'}}) {
if( $cur->{'offline'} =~ /false$/ ) {
if( !$cur->{'offline'} ) {
my $cat = $cur->{'displayName'};
$cat =~ s/\./\_/g;
if( $lcount > 0 ){
@ -130,7 +130,7 @@ if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
my %archs = ();
my $cat;
foreach my $cur(@{$parsed->{'computer'}}) {
if( $cur->{'offline'} =~ /false$/ ) {
if( !$cur->{'offline'} ) {
$cat = $cur->{'monitorData'}{'hudson.node_monitors.ArchitectureMonitor'};
if (exists $archs{$cat} ) {} else {
$archs{$cat} = 0;
@ -178,7 +178,7 @@ if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
my $total_mem = 0;
my $used_mem = 0;
foreach my $cur(@{$parsed->{'computer'}}) {
if( $cur->{'offline'} =~ /false$/ ) {
if( !$cur->{'offline'} ) {
$monitor = $cur->{'monitorData'}{'hudson.node_monitors.SwapSpaceMonitor'};
$avail_mem += $monitor->{'availablePhysicalMemory'};
$total_mem += $monitor->{'totalPhysicalMemory'};
@ -193,7 +193,7 @@ if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
my $result = `$cmd/computer/api/json`;
my $parsed = decode_json($result);
foreach my $cur(@{$parsed->{'computer'}}) {
if( $cur->{'offline'} =~ /false$/ ) {
if( !$cur->{'offline'} ) {
$monitor = $cur->{'monitorData'}{'hudson.node_monitors.SwapSpaceMonitor'};
my $cat = $cur->{'displayName'};
$cat =~ s/\./\_/g;
@ -206,7 +206,7 @@ if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
my $result = `$cmd/computer/api/json`;
my $parsed = decode_json($result);
foreach my $cur(@{$parsed->{'computer'}}) {
if( $cur->{'offline'} =~ /false$/ ) {
if( !$cur->{'offline'} ) {
$monitor = $cur->{'monitorData'}{'hudson.node_monitors.TemporarySpaceMonitor'};
my $cat = $cur->{'displayName'};
$cat =~ s/\./\_/g;
@ -219,7 +219,7 @@ if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
my $result = `$cmd/computer/api/json`;
my $parsed = decode_json($result);
foreach my $cur(@{$parsed->{'computer'}}) {
if( $cur->{'offline'} =~ /false$/ ) {
if( !$cur->{'offline'} ) {
$monitor = $cur->{'monitorData'}{'hudson.node_monitors.DiskSpaceMonitor'};
my $cat = $cur->{'displayName'};
$cat =~ s/\./\_/g;
@ -233,7 +233,7 @@ if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
my %archs = ();
my $cat;
foreach my $cur(@{$parsed->{'computer'}}) {
if( $cur->{'offline'} =~ /false$/ ) {
if( !$cur->{'offline'} ) {
$cat = $cur->{'monitorData'}{'hudson.node_monitors.ArchitectureMonitor'};
if (exists $archs{$cat} ) {
$archs{$cat} += 1;