2020-08-06 19:46:39 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2020-08-06 19:09:56 +02:00
|
|
|
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())
|