Compare commits

...

3 Commits

Author SHA1 Message Date
Patrick Neff 2895c53225 Merge branch 'master' into icinga 2020-08-06 19:50:29 +02:00
Patrick Neff 994c3093b5 Add shebang line 2020-08-06 19:46:39 +02:00
Patrick Neff 73cc05bda5 Add icinga scripts 2020-08-06 19:09:56 +02:00
2 changed files with 106 additions and 0 deletions

51
icinga-host-message.py Executable file
View File

@ -0,0 +1,51 @@
#!/usr/bin/env python
import os
import socket
from matrix_bot.bot import Bot
from matrix_bot.message import MarkdownMessage
from matrix_bot.utils import run_async
ROOM_ID = os.environ.get('MATRIX_ROOM_ID',
'!wDuJbnZXXNhbdPPcsW:gaja-group.com')
HOSTADDRESS = os.environ.get('HOSTADDRESS', None)
HOSTADDRESS6 = os.environ.get('HOSTADDRESS6', None)
NOTIFICATIONAUTHORNAME = os.environ.get('NOTIFICATIONAUTHORNAME', None)
NOTIFICATIONCOMMENT = os.environ.get('NOTIFICATIONCOMMENT', None)
LONGDATETIME = os.environ.get('LONGDATETIME', None)
MAILFROM = os.environ.get('MAILFROM', None)
ICINGAWEB2URL = os.environ.get('ICINGAWEB2URL', None)
ICINGA2HOST = os.environ.get('ICINGA2HOST', socket.gethostname())
HOSTNAME = os.environ.get('HOSTNAME', None)
HOSTDISPLAYNAME = os.environ.get('HOSTDISPLAYNAME', None)
HOSTOUTPUT = os.environ.get('HOSTOUTPUT', None)
RECIPIENT = os.environ.get('RECIPIENT', None)
HOSTSTATE = os.environ.get('HOSTSTATE', None)
NOTIFICATIONTYPE = os.environ.get('NOTIFICATIONTYPE', None)
VERBOSE = os.environ.get('VERBOSE', None)
def create_message() -> str:
message = (f'**HOST [{HOSTSTATE}]: {HOSTDISPLAYNAME} ({HOSTADDRESS})**'
f'\n\n{HOSTOUTPUT}')
if NOTIFICATIONCOMMENT:
message = f'{message}\n\nComment: {NOTIFICATIONCOMMENT}'
return message
async def main() -> None:
bot = Bot()
client = await bot.login()
await bot.sync()
room = await bot.find_room_by_id(ROOM_ID)
msg = create_message()
message = MarkdownMessage(msg)
await message.send(client, room)
await bot.shutdown()
if __name__ == '__main__':
run_async(main())

55
icinga-service-message.py Executable file
View File

@ -0,0 +1,55 @@
#!/usr/bin/env python
import os
import socket
from matrix_bot.bot import Bot
from matrix_bot.message import MarkdownMessage
from matrix_bot.utils import run_async
ROOM_ID = os.environ.get('MATRIX_ROOM_ID',
'!wDuJbnZXXNhbdPPcsW:gaja-group.com')
HOSTADDRESS = os.environ.get('HOSTADDRESS', None)
HOSTADDRESS6 = os.environ.get('HOSTADDRESS6', None)
NOTIFICATIONAUTHORNAME = os.environ.get('NOTIFICATIONAUTHORNAME', None)
NOTIFICATIONCOMMENT = os.environ.get('NOTIFICATIONCOMMENT', None)
LONGDATETIME = os.environ.get('LONGDATETIME', None)
MAILFROM = os.environ.get('MAILFROM', None)
ICINGAWEB2URL = os.environ.get('ICINGAWEB2URL', None)
ICINGA2HOST = os.environ.get('ICINGA2HOST', socket.gethostname())
HOSTNAME = os.environ.get('HOSTNAME', None)
HOSTDISPLAYNAME = os.environ.get('HOSTDISPLAYNAME', None)
SERVICENAME = os.environ.get('SERVICENAME', None)
SERVICEOUTPUT = os.environ.get('SERVICEOUTPUT', None)
SERVICESTATE = os.environ.get('SERVICESTATE', None)
SERVICEDISPLAYNAME = os.environ.get('SERVICEDISPLAYNAME', None)
RECIPIENT = os.environ.get('RECIPIENT', None)
NOTIFICATIONTYPE = os.environ.get('NOTIFICATIONTYPE', None)
VERBOSE = os.environ.get('VERBOSE', None)
def create_message() -> str:
message = (
f'**SERVICE [{SERVICESTATE}]: {SERVICENAME} on {HOSTDISPLAYNAME} '
f'({HOSTADDRESS})**\n\n{SERVICEOUTPUT}')
if NOTIFICATIONCOMMENT:
message = f'{message}\n\nComment: {NOTIFICATIONCOMMENT}'
return message
async def main() -> None:
bot = Bot()
client = await bot.login()
await bot.sync()
room = await bot.find_room_by_id(ROOM_ID)
msg = create_message()
message = MarkdownMessage(msg)
await message.send(client, room)
await bot.shutdown()
if __name__ == '__main__':
run_async(main())