Kumishifts
Kumishifts is an application that allows you to create files based on a Google Calendar and a separate configuration file. We (are going to) use it for generating Nagios contacts, to make sure only the person who's running the current shift gets notified of services and hosts that go down and another person gets notified on an escalation. But there are certainly more applications for this script.
It's written in Python and requires vobject and dateutil. On Debian, you can get these by doing:
apt-get install python-vobject python-dateutil
You can get the script itself by doing a Git checkout:
git clone http://git.kumina.nl/kumishifts.git kumishifts
There's a sample configuration file in the repository. It uses the current directory to read the config and the template and store the generated file. It uses /tmp for caching purposes. Change as you see fit. Once we create the Debian package for this, we'll follow Debian conventions for these, of course.
The data file, called contacts.cfg in the current repo, is a file on a remote server that contains the valid values for the contacts. An example file would be like this:
[contacts] Tim=0611111111 Kees=0622222222 Mike=0633333333 [contactgroups] Tim=Tim,Kees Kees=Kees,Mike Mike=Mike,Tim
We have two important events in our Google Calendar, being the "Tim helpdesk" event and the "Tim 24x7 storingsdienst" event. The name differs per the intended shift, of course. In this case, the application will start with downloading the contacts.cfg and ical file, see that currently "Tim" has both helpdesk and 24x7 shift and then proceeds to check this with the "contactgroups" as mentioned in the file above. It noticed that behind the "Tim" identifier, there are two names. It will get the phone numbers (under contacts) for the persons named behind the identifier in contactgroups.
Seems complex? Yeah, still need to find a way to make it a little more obvious.
Currently, the app is hardcoded to set the following variables:
* pager_helpdesk_primary * pager_helpdesk_secondary * pager_shift_primary * pager_shift_secondary
These will be changed into the relevant phone number when creating the file based on the template. You probably want to see what the method doKuminaSpecific does, so you can change it to do what you need it to do. This is something I'm planning on making easier, of course.
The current template I have is the following:
define contact {
contact_name primary-helpdesk
alias Primary contact for Helpdesk shift
host_notifications_enabled 1
service_notifications_enabled 1
host_notifications_period helpdesk
service_notifications_period helpdesk
host_notification_options d,u,r
service_notification_options w,u,c,r
host_notification_commands notify-by-sms
service_notification_commands host-notify-by-sms
pager ${pager_helpdesk_primary}
}
define contact {
contact_name secondary-helpdesk
alias Primary contact for Helpdesk shift
host_notifications_enabled 1
service_notifications_enabled 1
host_notifications_period helpdesk
service_notifications_period helpdesk
host_notification_options d,u,r
service_notification_options w,u,c,r
host_notification_commands notify-by-sms
service_notification_commands host-notify-by-sms
pager ${pager_helpdesk_secondary}
}
define contact {
contact_name primary-shift
alias Primary contact for rotating shift
host_notifications_enabled 1
service_notifications_enabled 1
host_notifications_period rotated-shift
service_notifications_period rotated-shift
host_notification_options d,u,r
service_notification_options w,u,c,r
host_notification_commands notify-by-sms
service_notification_commands host-notify-by-sms
pager ${pager_shift_primary}
}
define contact {
contact_name secondary-shift
alias Primary contact for rotating shift
host_notifications_enabled 1
service_notifications_enabled 1
host_notifications_period rotated-shift
service_notifications_period rotated-shift
host_notification_options d,u,r
service_notification_options w,u,c,r
host_notification_commands notify-by-sms
service_notification_commands host-notify-by-sms
pager ${pager_shift_secondary}
}
define contactgroup {
contactgroup_name primary
alias The people on 1st line duty
members primary-shift, primary-helpdesk
}
define contactgroup {
contactgroup_name secondary
alias The people on 2st line duty
members secondary-shift, secondary-helpdesk
}
Keep in mind you still need to define the time-periods yourself, we have those in a separate file and you probably want to create your own.
Please keep in mind that I'm a sysadmin by trade and this has been a hobby project on the side for me. I'm not even close to a programmer, I just dabble a bit in the Arts. I hope someone more skilled than me is willing to fix my code! For now, it works as intended for us.
Patches, comments, questions and patches can be sent to Tim Stoop. Please put kumishifts in the subject line. If there's enough interest in this, I'll add a mailinglist.
