...
Code Block | ||
---|---|---|
| ||
package Event_State_Example; our $VERSION="0.0.0"; use lib "/usr/local/omk/lib"; use strict; #use func; use OMK::Common; use Data::Dumper; use OMK::opEvents; use OMK::Log; # arguments: the line (currently being parsed), # and reference to the live event properties # returns: (status-or-error) # # zero or undef: parsing for this event is aborted, # and no event is created. # 1: indicates success, event is created and changed event # properties are incorporated. # any other value: treated as error message, changed event # properties are NOT incorporated but event parsing continues. sub parse_enrich { my ($line, $event, $OPE) = @_; my ($line, $event) = @_; my $confCommon = loadOmkConfTable(conf=> "opCommon", dir=> "/usr/local/omk/conf"); my $logger = OMK::Log->new(level => $confCommon->{"omkd_log_level"} || 'info', path => $confCommon->{'<omk_logs>'}."/opEvents.log"); my $OPE = OMK::opEvents->new(config => $confCommon, logprefix => "Plugin::Event_State_Example", log => $logger); $OPE->getDb(); #We can get an event with an id my $modelData = $OPE->getEventLogsModel(log_name => "events", id => '60516246c6c2b17094225a9c'); my $otherEvent = $modelData->[0]; $event->{other_event_ack} = []; my $thisuser = "Plugin::Event_State_Example"; #lets get an event by name and mark them acknowledged #you must pass time start and end if we are looking for events and not and event by an id #lets ack them foreach my $e (@{$toBeAcknowledged}){ my $now = time; my $failure = $OPE->updateEvent( "_id" => $e->{_id}, acknowledged => 1, status_history => [ $now, $thisuser, "acknowledged", 1 ], ); push @{$event->{other_event_ack}}, $e->{_id}->to_string; #TODO better error handling return if($failure); } $event->{Plugin_Used} = "Event_State_Example"; $event->{node} = "fulla-localhost"; $event->{host} = "127.0.0.1"; $event->{other_event} = $otherEvent->{_id}->to_string; return 1; } |
...