cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Syntax to send events from custom plugins

olivier_weinsto
Participant

Hi,I'm actually trying to write dynatrace custom plugins and I want to send events from the plugin.

I've seen the add_event(event) method but doesn't find any documentation on the event object that must be sent

can you give an example?

thanks

Olivier

2 REPLIES 2

Julius_Loman
Leader

See the API itself in <oneagent dir>/agent/plugin/engine/ruxit/api/events.py

For inspiration, how to call it, see the openstack notifications plugin (notifications_openstack_plugin.py) available with oneagent itself. However I don't think this can be considered "stable", since it's not yet in the documentation and it probably may change in the future.

TEMPEST a.s., Slovakia, Dynatrace Master Partner

olivier_weinsto
Participant

Hi,

I tried the syntax from the openstack plugin but don't know which value to put in the keys. I try to make a plugin which reports an event when a user logs in to a server and which reports the number of logged in users. The metric is reported but no events

Here is my code if you have an idea:

import subprocess
from ruxit.api.base_plugin import BasePlugin
from ruxit.api.snapshot import pgi_name




class AuthPlugin(BasePlugin):
def query(self, **kwargs):
pgi = self.find_single_process_group(pgi_name('sshd'))
pgi_id = pgi.group_instance_id
result = subprocess.run('lastlog -t1 | grep `date +%H:%M` | awk \'{print $1}\'', shell=True, stdout=subprocess.PIPE)
lines=result.stdout.decode('utf8').split()
for line in lines:
self.results_builder.add_event(
Event(1, pgi_id,
EventMetadata(key=1,
value=line+"logged in")))


result = subprocess.run('ps -fe | grep sshd | grep pts | grep -v grep | wc -l', shell=True, stdout=subprocess.PIPE)
lines=result.stdout.decode('utf8').split()
for line in lines:
self.results_builder.absolute(key='loggedusers', value=line, entity_id=pgi_id)
~