--- lib/PXElator/amt.pm 2009/08/30 13:33:59 375 +++ lib/PXElator/amt.pm 2009/08/30 15:22:41 376 @@ -12,22 +12,39 @@ use html; use ping; use CouchDB; +use Carp qw/confess/; -sub info { - my ( $amt, $client_ip ) = @_; - my ( $passwd, $ip ) = split(/\s+/, $amt); +sub ip { + my $client_ip = shift || confess "no ip"; + my ( $passwd, $ip ) = split(/\s+/, client::conf( $client_ip => 'amt' )); ( $ip, $passwd ) = ( $passwd, $ip ) if $passwd =~ m/$RE{net}{IPv4}/; $ip ||= $client_ip; if ( ! ping::host( $ip ) ) { - warn "$ip unreachable"; + warn "W: ping $ip unreachable\n"; } warn "amt $ip ", '*' x length($passwd), "\n"; - $ENV{AMT_HOST} = $ip; $ENV{AMT_PASSWORD} = $passwd; + $ENV{AMT_HOST} = $ip; + +} + +sub power_on { + ip @_; + power_state() == 0; +} + +sub power_state { + my $state = eval { Intel::AMT::RemoteControl::SystemPowerState }; + CouchDB::audit('SystemPowerState', { ip => $ENV{AMT_HOST}, SystemPowerState => $state }); + return $state; +} + +sub info { + ip @_; my $amt; eval { @@ -38,6 +55,7 @@ warn "ERROR amt $@" if $@; my $out; + my $ip = $ENV{AMT_HOST}; $out = qq| amt| @@ -49,4 +67,13 @@ return $out; } + +sub RemoteControl { + ip shift; + my $command = shift; + eval { Intel::AMT::RemoteControl::run( $command ) }; + CouchDB::audit( $command, { ip => $ENV{AMT_HOST}, error => $@ } ); + warn "ERROR $@" if $@; +} + 1;