Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

...

Much more clean and simple!

opEvents gt 3.2.4 - Sending an event to NMIS 

It is also possible to send an event to NMIS using nmisx object: 

Code Block
    my $OPE = OMK::opEvents->new(config => $confCommon,
								logprefix => "Plugin::TestPlugin, ",
								log => $logger);
	$OPE->getDb();

	my $nmisx = $OPE->{nmisx};
	my $event = {
		node => "asgard-local",
		event => "Event from opEvents plugin",
		element => "plugin",
		details => "Event from opEvents plugin details",
		level => 8
	};
	my $response = $nmisx->createNmisEvent(event => $event);
	$OPE->log->info("MYParserPlugin:: Response: \n" . Dumper($response));


Getting events: getEventLogsModel

...

Code Block
languageperl
'_id' => $arg{id},
'time' => { '$gte' => $time_start, '$lt' => $time_end },
'event' => $arg{event},
'node_uuid' => $arg{node_uuid},
'type' => $arg{type},
'element' => $arg{element},
'details' => $arg{details},
'eventid' => $arg{event_id}, # only useful in actionlog
'action' => $arg{action}, # only useful in actionlog
'archive' => $arg{archive}, # only useful in archive log
'entry' => $arg{entry}, # only in raw log
'state' => $arg{state},
'nodeinfo.configuration.location' => {'$regex' => $arg{'nodeinfo.configuration_location'} || $arg{location}},
'nodeinfo.configuration.group' => {'$regex' => $arg{'nodeinfo.configuration_group'} || $arg{group}},
'acknowledged' => numify($arg{acknowledged}),
'escalate' => numify($arg{escalate}),
'priority' => numify($arg{priority}), });

Creating Events

opEvents object provides an easy way to create an event: 


Code Block
# Tell opEvents object to create the event
my ($error, $eventid) = $OPE->createEvent(event => $event);

...

Code Block
# Create Event Object
my $event = {};

my @maybeprops = grep($_ !~ /^(act|debug|quiet|conf|confdir|baseurl|username|password)$/, keys %$Q);
if (@maybeprops)
{
	my @rawinputs;
	for my $key (@maybeprops)
	{
		next if ($Q->{$key} eq ''); # supress empty properties
		die "argument $key cannt be set multiple times!\n" if (ref($Q->{$key}) eq "ARRAY");

		# ensure numeric values for anything numeric, or mongo comparison ops will
		# fail badly (especially true for time, which breaks the gui)
		$event->{$key} = numify($Q->{$key});
		push @rawinputs, "'$key=$Q->{$key}'";
	}
	$event->{entry} = join(" ", @rawinputs);
}


Updating Events

opEvents object also provides an easy way to update an event. We will need to pass the following arguments:

  • _id: for identify the event to be updated
  • _constraints: to disable db key munging

Everything else will be recorded as content, as-is, except "status_history" and "trigger_eventids"

  • status_history: optional but special: must be array and this array will be ADDED to an existing status_history array.
  • trigger_eventids: always saved as array, and a new value is ADDED.
  • buttons: always saved as array, and a new value is ADDED.

returns undef if ok, error message otherwise (also logged)

As an example:

Code Block
my $failure = $OPE->updateEvent( "_id" => $e->{_id},
								priority => 5,
								status_history => [ $now, $thisuser, "priority", 5 ], );

...