0
0
Fork 0
mirror of https://github.com/alerta/alerta.git synced 2025-01-24 17:29:39 +00:00
alerta_alerta/bin/alert-snmptrap
2013-03-03 10:48:32 +00:00

63 lines
No EOL
1.9 KiB
Python
Executable file

#!/usr/bin/env python
########################################
#
# alert-snmptrap - Alert SNMP Trap handler
#
########################################
import os
import sys
import argparse
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
os.pardir,
os.pardir))
if os.path.exists(os.path.join(possible_topdir, 'alerta', '__init__.py')):
sys.path.insert(0, possible_topdir)
from alerta.common import config
from alerta.common import log as logging
from alerta.snmptrap.handler import SnmpTrapHandler, Version
DEFAULT_TIMEOUT = 86400
LOG = logging.getLogger('alerta.snmptrap')
CONF = config.CONF
def main(argv):
try:
parser = argparse.ArgumentParser(
add_help=False,
prog='alert-sender',
description='Alert Command-Line Tool - sends an alert to the alerting system. Alerts must have' +
' a resource (including service and environment), event name, value and text. A ' +
'severity of "Normal" is used if none given. Tags and group are optional.',
epilog='alert-sender.py --resource myCoolApp --event AppStatus --group Application --value Down ' +
'--severity critical --env PROD --svc MicroApp --tag release:134 --tag build:1005 ' +
'--text "Micro App X is down."'
)
parser.add_argument(
'-d',
'--dry-run',
action='store_true',
default=False,
help='Do not send alert.'
)
argv = ['--debug']
config.parse_args(argv, version=Version)
logging.setup('alerta')
handler = SnmpTrapHandler()
handler.run()
except Exception, e:
print >> sys.stderr, e
sys.exit(1)
if __name__ == '__main__':
main(sys.argv[1:])