holidays
Thibault Genessay
tgenessay at aliadis.fr
Fri Oct 6 15:37:06 CEST 2006
Andreas Ericsson wrote:
> Bart van Daal wrote:
>> Hi list,
>>
>>
>> i've been searching around for a way to define holidays in nagios. The
>> object is
>> to be able to use a 24-7 timeperiod on holidays (e.g. 25 december) and
>> the Tech_hours
>> timeperiod on 'normal' days:
>>
>
> afaik, there are no solutions for this inside Nagios. Most people who
> need this desperately enough have implemented the functionality in the
> notification-script. I believe the reason no solution has been posted
> online is that whatever solution is used isn't sharable across national
> borders.
>
Yep, Nagios did not help us for that so we have implemented it in a
custom notification script. In fact, Nagios is configured for everything
in 24x7 notification periods, and the script does the filtering, so
Nagios ignores whether any notification is actually sent. This might
seem uncomfortable, but we've been using this technique for quite a long
time now and no problem ever arouse from it.
Here is a snippet from our Python notification script, if it can help
you write your own. Please note that the holidays are the french ones,
you'll need to add/remove yours, depending on your country.
#!/usr/bin/python
# Algorithm: http://smart.net/~mmontes/oudin.html
def getEasterDate(year):
century = year/100
G = year % 19
K = (century - 17)/25
I = (century - century/4 - (century - K)/3 + 19*G + 15) % 30
I = I - (I/28)*(1 - (I/28)*(29/(I + 1))*((21 - G)/11))
J = (year + year/4 + I + 2 - century + century/4) % 7
L = I - J
EasterMonth = 3 + (L + 40)/44
EasterDay = L + 28 - 31*(EasterMonth/4)
return time.mktime([year, EasterMonth, EasterDay, 0, 0, 0, 0, 0, -1])
def getPublicHolidays(year):
easter = getEasterDate(year)
day = 3600*24
days = []
# lundi de paques
days.append(easter + day)
# ascension
days.append(easter + 39*day)
# vendredi saint (alsace, suisse)
## days.append(time.gmtime(easter - 2*day))
# lundi de pentecote
days.append(easter + 50*day)
# fetes fixes
days.append(time.mktime([year,1,1,1,0,0,0,0,-1])) # jour de l'an
days.append(time.mktime([year,5,1,1,0,0,0,0,-1])) # fete du travail
days.append(time.mktime([year,5,8,1,0,0,0,0,-1])) # armistice 39-45
days.append(time.mktime([year,7,14,1,0,0,0,0,-1])) # fete nationale
days.append(time.mktime([year,8,15,1,0,0,0,0,-1])) # assomption
days.append(time.mktime([year,11,1,1,0,0,0,0,-1])) # toussaint
days.append(time.mktime([year,11,11,1,0,0,0,0,-1])) # armistice 14-48
days.append(time.mktime([year,12,25,1,0,0,0,0,-1])) # noel
return days
if name == '__main__':
[...]
holidays = getPublicHolidays(thisyear)
curtime = time.localtime() # a struct_time with
year/month/mday/H/M/S/yday/wday/dst
curtimets = time.time() # a UNIX timestamp
is_holiday = False
holidays = getPublicHolidays(curtime.tm_year)
dayspan = 3600*24;
for day in holidays:
if curtimets >= day and curtimets < day+dayspan:
is_holiday = True #damn
break
# Now you can do whatever you want with your message: decide to
send it or not based on the value of is_holiday.
--
Thibault GENESSAY
ALIADIS
www.aliadis.fr
Tel. +33 4 72 13 90 40
Fax +33 4 74 22 00 09
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue.
::: Messages without supporting info will risk being sent to /dev/null
More information about the Users
mailing list