nagios conference 2012 - dave josephsen - stop being lazy
TRANSCRIPT
Stop being lazy and writean event broker module already
Dave Josephsen
WHY?!
The NEB interface is AWESOME
Interpreted automata is expensiveEspecially via global event handlers and/or performance-data hooks
You're more likely to make something I can use too!
How we're going to do this
Function pointers (and YOU)
What is the event broker?
How do we use it?
A few words of advice
Dissect a couple existing pluginsNagfs
DNX
Function Pointers are weird, but they make callbacks possible
void main() {
int c2f ( int c ) { return (9/5) *c+32; } int f2c ( int f ) { return (5/9) *(f-32); }
int convert (int input, int (*fPointer)(int)) { return fPointer(input);
}
void Go() {
int result=convert('72',&f2c);
}
}
Normal Function Declarations
wha??
Argument
Oh.. ok.
What is the event broker?
Nagios Event loop(kinda)
Event Broker added
How do we use it?
Write an init functionint nebmodule_init( int flags, char * args, nebmodule * handle)
Subscribe to the events you wantneb_register_callback(STUFF, handle, '1', &myhandler);
Write handler functions for each event you subscribed toint myhandler(int neb_event_type, nebstruct_stuff_data *ds)
Write a de-init functionint nebmodule_deinit(int flags, int reason){ return 0 }
How do we use it? (cont)
NEBCALLBACK_RAW_DATANEBCALLBACK_NEB_DATANEBCALLBACK_PROCESS_DATANEBCALLBACK_TIMED_EVENT_DATANEBCALLBACK_LOG_DATANEBCALLBACK_SYSTEM_COMMAND_DATANEBCALLBACK_EVENT_HANDLER_DATANEBCALLBACK_NOTIFICATION_DATANEBCALLBACK_SERVICE_CHECK_DATANEBCALLBACK_HOST_CHECK_DATANEBCALLBACK_COMMENT_DATANEBCALLBACK_DOWNTIME_DATANEBCALLBACK_FLAPPING_DATANEBCALLBACK_PROGRAM_STATUS_DATANEBCALLBACK_HOST_STATUS_DATANEBCALLBACK_SERVICE_STATUS_DATANEBCALLBACK_ADAPTIVE_PROGRAM_DATANEBCALLBACK_ADAPTIVE_HOST_DATANEBCALLBACK_ADAPTIVE_SERVICE_DATANEBCALLBACK_EXTERNAL_COMMAND_DATANEBCALLBACK_AGGREGATED_STATUS_DATANEBCALLBACK_RETENTION_DATANEBCALLBACK_CONTACT_NOTIFICATION_DATANEBCALLBACK_CONTACT_NOTIFICATION_METHOD_DATANEBCALLBACK_ACKNOWLEDGEMENT_DATANEBCALLBACK_STATE_CHANGE_DATANEBCALLBACK_CONTACT_STATUS_DATANEBCALLBACK_ADAPTIVE_CONTACT_DATA
include/nebcallbacks.h
neb_register_callback(NEBCALLBACK_TIMED_EVENT_DATA, handle, '1', &handler);
/* fill struct with relevant data */ ds.type=type; ds.flags=flags; ds.attr=attr; ds.timestamp=get_broker_timestamp(timestamp);
ds.event_type=event->event_type; ds.recurring=event->recurring; ds.run_time=event->run_time; ds.event_data=event->event_data; ds.event_ptr=(void *)event;
/* make callbacks */ neb_make_callbacks(NEBCALLBACK_TIMED_EVENT_DATA,(void *)&ds);
base/broker.c
include/broker.h
#define NEBTYPE_TIMEDEVENT_ADD #define NEBTYPE_TIMEDEVENT_REMOVE #define NEBTYPE_TIMEDEVENT_EXECUTE#define NEBTYPE_TIMEDEVENT_DELAY#define NEBTYPE_TIMEDEVENT_SKIP#define NEBTYPE_TIMEDEVENT_SLEEP
int handler(int neb_event_type, nebstruct_timed_event_data *ds)
How do we use it? (cont)
Everything is a struct
Every struct is globally scoped
The sky is the limitenumerate/add/remove events from the queue
reconfigure hosts/services post-runtime
export/import data from/to whatever
process check data, inject/delete check results
GO CRAZY!
Some words of advice
There's a hello world module in contrib
Write your thingy as a stand-alone thingy first, and then convert it to an EH function
Start simple, and then build up
Avoid Threads(run them in a separate process)
The DNX guys have pre-packaged the headers for various versions of Nagios (zomgthankyou)
Nagfs
DNX
External process IPC
Service check preemption
Check result injection
OK BYE!
(and speaking of buy...)
http://dnx.sourceforge.net/
http://old.nagios.org/developerinfo/
http://nagios.larsmichelsen.com/event_broker_options/
Click to edit the outline text format
Second Outline Level
Third Outline Level
Fourth Outline Level
Fifth Outline Level
Sixth Outline Level
Seventh Outline Level
Eighth Outline Level
Ninth Outline Level
Click to edit the title text format
2012
Click to edit the title text format
Click to edit the outline text formatSecond Outline LevelThird Outline LevelFourth Outline LevelFifth Outline LevelSixth Outline LevelSeventh Outline LevelEighth Outline LevelNinth Outline Level