/[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

Contents of /lib/PXElator/amt.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 385 - (show 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 package amt;
2
3 use warnings;
4 use strict;
5
6 use lib '/srv/Intel-AMT/lib/';
7 use Intel::AMT::RemoteControl;
8 use Intel::AMT::NetworkAdministration;
9 use Intel::AMT::EventManager;
10 use Data::Dump qw/dump/;
11 use Regexp::Common qw/net/;
12
13 use html;
14 use ping;
15 use CouchDB;
16 use Carp qw/confess/;
17
18 sub ip {
19 my ( $client_ip, $amt ) = @_;
20 return unless $client_ip;
21 $amt ||= client::conf( $client_ip => 'amt' );
22 my ( $passwd, $ip ) = split(/\s+/, $amt);
23 ( $ip, $passwd ) = ( $passwd, $ip ) if $passwd =~ m/$RE{net}{IPv4}/;
24
25 $ip ||= $client_ip;
26
27 $ENV{AMT_PASSWORD} = $passwd;
28 $ENV{AMT_HOST} = $ip;
29 }
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 sub power_on {
38 ip @_;
39 my $state = power_state;
40 defined $state && ( $state & 0x0f ) == 0;
41 }
42
43 sub network {
44 ip @_;
45
46 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 $amt;
54 }
55
56 sub log {
57 ip @_;
58
59 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 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 1;

  ViewVC Help
Powered by ViewVC 1.1.26