52 lines
1.6 KiB
Python
Executable File
52 lines
1.6 KiB
Python
Executable File
#!/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())
|