diff --git a/perl-xCAT/xCAT/Schema.pm b/perl-xCAT/xCAT/Schema.pm index 788902c1e..8309cc40a 100644 --- a/perl-xCAT/xCAT/Schema.pm +++ b/perl-xCAT/xCAT/Schema.pm @@ -595,10 +595,10 @@ eventlog => { eventtime => 'The timestamp for the event.', monitor => 'The name of the monitor that monitors this event.', #in RMC, it's the condition name monnode => 'The node that monitors this event.', - node => 'The node where the event occurred', + node => 'The node where the event occurred.', application => 'The application that reports the event.', #RMC, Ganglia component => 'The component where the event occurred.', #in RMC, it's the resource class name - id => 'The location or the resource name where the event occurred', #In RMC it's the resource name and attribute name + id => 'The location or the resource name where the event occurred.', #In RMC it's the resource name and attribute name severity => 'The severity of the event. Valid values are: informational, warning, critical.', message => 'The full description of the event.', rawdata => ' The data that associated with the event. ', # in RMC, it's the attribute value, it takes the format of attname=attvalue[,atrrname=attvalue....] @@ -673,6 +673,7 @@ foreach my $tabname (keys(%xCAT::ExtTab::ext_tabspec)) { policy => { attrs => [], attrhash => {}, objkey => 'priority' }, monitoring => { attrs => [], attrhash => {}, objkey => 'name' }, notification => { attrs => [], attrhash => {}, objkey => 'filename' }, + eventlog => { attrs => [], attrhash => {}, objkey => 'recid' }, ); @@ -1470,6 +1471,62 @@ push(@{$defspec{group}->{'attrs'}}, @nodeattrs); }, ); +@{$defspec{eventlog}->{'attrs'}} = ( + {attr_name => 'recid', + tabentry => 'eventlog.recid', + access_tabentry => 'eventlog.recid=attr:recid', + }, + {attr_name => 'eventtime', + tabentry => 'eventlog.eventtime', + access_tabentry => 'eventlog.recid=attr:recid', + }, + {attr_name => 'monitor', + tabentry => 'eventlog.monitor', + access_tabentry => 'eventlog.recid=attr:recid', + }, + {attr_name => 'monnode', + tabentry => 'eventlog.monnode', + access_tabentry => 'eventlog.recid=attr:recid', + }, + {attr_name => 'node', + tabentry => 'eventlog.node', + access_tabentry => 'eventlog.recid=attr:recid', + }, + {attr_name => 'application', + tabentry => 'eventlog.application', + access_tabentry => 'eventlog.recid=attr:recid', + }, + {attr_name => 'component', + tabentry => 'eventlog.component', + access_tabentry => 'eventlog.recid=attr:recid', + }, + {attr_name => 'id', + tabentry => 'eventlog.id', + access_tabentry => 'eventlog.recid=attr:recid', + }, + {attr_name => 'severity', + tabentry => 'eventlog.severity', + access_tabentry => 'eventlog.recid=attr:recid', + }, + {attr_name => 'message', + tabentry => 'eventlog.message', + access_tabentry => 'eventlog.recid=attr:recid', + }, + {attr_name => 'rawdata', + tabentry => 'eventlog.rawdata', + access_tabentry => 'eventlog.recid=attr:recid', + }, + {attr_name => 'comments', + tabentry => 'eventlog.comments', + access_tabentry => 'eventlog.recid=attr:recid', + }, + {attr_name => 'disable', + tabentry => 'eventlog.disable', + access_tabentry => 'eventlog.recid=attr:recid', + }, +); + + diff --git a/perl-xCAT/xCAT/Utils.pm b/perl-xCAT/xCAT/Utils.pm index 2662e28bf..3ae62171a 100644 --- a/perl-xCAT/xCAT/Utils.pm +++ b/perl-xCAT/xCAT/Utils.pm @@ -2869,4 +2869,58 @@ sub get_image_name { } +#------------------------------------------------------------------------------- + +=head3 logEventsToDatabase + Logs the given events info to the xCAT's 'eventlog' database + Arguments: + arrayref -- A pointer to an array. Each element is a hash that contains an events. + The hash should contain the at least one of the following keys: + eventtime -- The format is "mm-dd-yyyy hh:mm:ss". + If omitted, the current date and time will be used. + monitor -- The name of the monitor that monitors this event. + monnode -- The node that monitors this event. + node -- The node where the event occurred. + application -- The application that reports the event. + component -- The component where the event occurred. + id -- The location or the resource name where the event occurred. + severity -- The severity of the event. Valid values are: informational, warning, critical. + message -- The full description of the event. + rawdata -- The data that associated with the event. + Returns: + (ret code, error message) + +=cut + +#------------------------------------------------------------------------------- +sub logEventsToDatabase{ + my $pEvents=shift; + if (($pEvents) && ($pEvents =~ /xCAT::Utils/)) { + $pEvents=shift; + } + + if (($pEvents) && (@$pEvents > 0)) { + my $currtime; + my $tab = xCAT::Table->new("eventlog",-create => 1,-autocommit => 0); + if (!$tab) { + return (1, "The evnetlog table cannot be opened."); + } + + foreach my $event (@$pEvents) { + #create event time if it does not exist + if (!exists($event->{eventtime})) { + if (!$currtime) { + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); + $currtime=sprintf("%02d-%02d-%04d %02d:%02d:%02d", $mon+1,$mday,$year+1900,$hour,$min,$sec); + } + $event->{eventtime}=$currtime; + } + $tab->setAttribs(undef, $event); + } + $tab->commit; + } + + return (0, ""); +} + 1;