/[pxelator]/lib/PXElator/amt.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /lib/PXElator/amt.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 385 - (hide annotations)
Sun Aug 30 22:46:57 2009 UTC (14 years, 7 months ago) by dpavlin
File size: 1502 byte(s)
collect amt event logs
1 dpavlin 181 package amt;
2    
3     use warnings;
4     use strict;
5    
6 dpavlin 191 use lib '/srv/Intel-AMT/lib/';
7 dpavlin 181 use Intel::AMT::RemoteControl;
8     use Intel::AMT::NetworkAdministration;
9 dpavlin 385 use Intel::AMT::EventManager;
10 dpavlin 181 use Data::Dump qw/dump/;
11 dpavlin 186 use Regexp::Common qw/net/;
12 dpavlin 181
13     use html;
14 dpavlin 330 use ping;
15 dpavlin 263 use CouchDB;
16 dpavlin 376 use Carp qw/confess/;
17 dpavlin 181
18 dpavlin 376 sub ip {
19 dpavlin 380 my ( $client_ip, $amt ) = @_;
20 dpavlin 385 return unless $client_ip;
21 dpavlin 380 $amt ||= client::conf( $client_ip => 'amt' );
22     my ( $passwd, $ip ) = split(/\s+/, $amt);
23 dpavlin 186 ( $ip, $passwd ) = ( $passwd, $ip ) if $passwd =~ m/$RE{net}{IPv4}/;
24 dpavlin 181
25 dpavlin 262 $ip ||= $client_ip;
26    
27 dpavlin 376 $ENV{AMT_PASSWORD} = $passwd;
28 dpavlin 181 $ENV{AMT_HOST} = $ip;
29 dpavlin 376 }
30    
31     sub power_state {
32     my $state = eval { Intel::AMT::RemoteControl::SystemPowerState };
33     CouchDB::audit('SystemPowerState', { ip => $ENV{AMT_HOST}, SystemPowerState => $state });
34     return $state;
35     }
36    
37 dpavlin 380 sub power_on {
38     ip @_;
39     my $state = power_state;
40     defined $state && ( $state & 0x0f ) == 0;
41     }
42    
43 dpavlin 385 sub network {
44 dpavlin 376 ip @_;
45    
46 dpavlin 385 my $amt = eval { Intel::AMT::NetworkAdministration::network_settings };
47     if ( $@ ) {
48     warn "ERROR $@";
49     } else {
50     $amt->{ip} = $ENV{AMT_HOST};
51     CouchDB::audit('log', $amt );
52     }
53 dpavlin 380 $amt;
54 dpavlin 181 }
55    
56 dpavlin 385 sub log {
57     ip @_;
58 dpavlin 376
59 dpavlin 385 my $amt = eval { Intel::AMT::EventManager::ReadEventLogRecords };
60     if ( $@ ) {
61     warn "ERROR $@";
62     } else {
63     $amt->{ip} = $ENV{AMT_HOST};
64     CouchDB::audit('log', $amt );
65     }
66     $amt;
67     }
68    
69 dpavlin 376 sub RemoteControl {
70     ip shift;
71     my $command = shift;
72     eval { Intel::AMT::RemoteControl::run( $command ) };
73     CouchDB::audit( $command, { ip => $ENV{AMT_HOST}, error => $@ } );
74     warn "ERROR $@" if $@;
75     }
76    
77 dpavlin 181 1;

  ViewVC Help
Powered by ViewVC 1.1.26