#!/usr/bin/env perl # # Description: Check of system uptimes via Siacewalk API # Results are displayed on stdout or redirected to a file # # Last Update: 5 Oct 2013 # Designed by: Dusan U. Baljevic (dusan.baljevic@ieee.org) # Coded by: Dusan U. Baljevic (dusan.baljevic@ieee.org) # # Copyright 2006-2015 Dusan Baljevic # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # The script has been developed over several hectic days, so errors # (although not planned) might exist. Please use with care. # # There are not many comments throught the script and that # is not best practices for writing good code. However, # I view this script as a learning tool for system administrators # too so lack of comments is partially left as an exercise. # $ENV{'PATH'} = "/bin:/usr/sbin:/sbin:/usr/bin:/usr/local/bin"; use strict; #!/usr/bin/perl use Frontier::Client; use strict; use warnings; use Time::Local; if ( eval "require DateTime::Format::ISO8601" ) { import DateTime::Format::ISO8601; } my $HOST = "mysathost"; # # Satellite username and password # my $user = 'myusername'; my $pass = 'mypassword'; my $dt = q{}; my $client = new Frontier::Client(url => "http://$HOST/rpc/api"); my $session = $client->call('auth.login',$user, $pass); my $systems = $client->call('system.listUserSystems', $session); foreach my $system (@$systems) { my $getinfo = $client->call('system.getDetails', $session, $system->{'id'}); foreach my $ginfo ($getinfo) { if ( eval "use DateTime::Format::ISO8601" ) { $dt = DateTime::Format::ISO8601->parse_datetime($ginfo->{'last_boot'}); print "Server $system->{'name'} (ID=$system->{'id'}) last boot: ".$dt->strftime('%F %T'); } else { $dt = sprintf("%d-%02d-%02d%s%s", unpack('A4A2A2AA8', $ginfo->{'last_boot'}->value())); } print "Server $system->{'name'} (ID=$system->{'id'}) last boot: $dt\n"; } } $client->call('auth.logout', $session); exit(0);