File check_buildservice_status.pl of Package monitoring-plugins-buildservice

#!/usr/bin/perl
use warnings;
use LWP::UserAgent;

 
    my @search_strings = ("i586", "x86_64", "dispatcher", "publisher");

    if (@ARGV < 2)
    {
        print "ERROR: No parameters set!";
        exit 3;
    }
    my $host = $ARGV[0]; #"http://buildservice.suse.de:5352";
    my $file = $ARGV[1]; #"/build/_workerstatus";
    my $ua = LWP::UserAgent->new;
        $ua->default_headers->push_header('Host' => $ARGV[0]);
                       
    my $response = $ua->get($host.$file);

    my @result;
    my $r_counter = 0;
    my $search_string;
    foreach $search_string (@search_strings)
    {
        if ($response->content =~ /<scheduler arch="($search_string)" state="([\w]+)" starttime=/)
        {
            $result[$r_counter]{arch} = $1;
            $result[$r_counter]{state} = $2;
            $r_counter++;
        }
    }
#$result[1]{state} = "blubb";
    my $exit_code = 0; #every thing is fine;
    my $exit_message = "";
    for (my $i = 0; $i <= $r_counter-1; $i++)
    {
        if ($result[$i]{state} ne "running")
        {
            $exit_code = 2;
            $exit_message .= $result[$i]{arch}."=".$result[$i]{state}." ";
        }
    }
    if ($exit_code == 0)
    {
        $exit_message = "Success, everything up and running";
    }
print $exit_message;
exit $exit_code;