mirror of
https://github.com/alerta/alerta.git
synced 2025-03-13 04:53:16 +00:00
add solarwinds event integration
This commit is contained in:
parent
06355a090b
commit
2fa9c73a75
7 changed files with 247 additions and 2 deletions
|
@ -86,8 +86,10 @@ def parse_args(argv, prog=None, version='unknown', cli_parser=None, daemon=True)
|
|||
'irc_channel': '#alerts',
|
||||
'irc_user': 'alerta',
|
||||
|
||||
'ganglia_host': 'ganglia',
|
||||
'ganglia_port': 8080,
|
||||
'solarwinds_host': 'solarwinds',
|
||||
'solarwinds_username': 'admin',
|
||||
'solarwinds_password': '',
|
||||
'solarwinds_group': 'websys',
|
||||
|
||||
'es_host': 'localhost',
|
||||
'es_port': 9200,
|
||||
|
|
0
alerta/solarwinds/__init__.py
Normal file
0
alerta/solarwinds/__init__.py
Normal file
136
alerta/solarwinds/daemon.py
Normal file
136
alerta/solarwinds/daemon.py
Normal file
|
@ -0,0 +1,136 @@
|
|||
|
||||
import sys
|
||||
import time
|
||||
import datetime
|
||||
|
||||
from alerta.common import config
|
||||
from alerta.common import log as logging
|
||||
from alerta.common.daemon import Daemon
|
||||
from alerta.common.alert import Alert
|
||||
from alerta.common.heartbeat import Heartbeat
|
||||
from alerta.common.dedup import DeDup
|
||||
from alerta.solarwinds.swis import SwisClient, SOLAR_WINDS_SEVERITY_LEVELS
|
||||
from alerta.common.mq import Messaging, MessageHandler
|
||||
|
||||
Version = '2.0.0'
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
CONF = config.CONF
|
||||
|
||||
|
||||
class SolarWindsMessage(MessageHandler):
|
||||
|
||||
def __init__(self, mq):
|
||||
self.mq = mq
|
||||
MessageHandler.__init__(self)
|
||||
|
||||
def on_disconnected(self):
|
||||
self.mq.reconnect()
|
||||
|
||||
|
||||
class SolarWindsDaemon(Daemon):
|
||||
|
||||
def run(self):
|
||||
|
||||
self.running = True
|
||||
|
||||
LOG.info('Starting SolarWinds poller %s %s...', CONF.solarwinds_username, CONF.solarwinds_password)
|
||||
try:
|
||||
swis = SwisClient(username=CONF.solarwinds_username, password=CONF.solarwinds_password)
|
||||
except Exception, e:
|
||||
LOG.error('SolarWinds SWIS Client error: %s', e)
|
||||
sys.exit(2)
|
||||
LOG.info('Polling for SolarWinds events on %s' % CONF.solarwinds_host)
|
||||
|
||||
# Connect to message queue
|
||||
self.mq = Messaging()
|
||||
self.mq.connect(callback=SolarWindsMessage(self.mq))
|
||||
|
||||
self.dedup = DeDup(by_value=True)
|
||||
|
||||
while not self.shuttingdown:
|
||||
try:
|
||||
LOG.debug('Polling SolarWinds...')
|
||||
|
||||
events = swis.get_events()
|
||||
|
||||
solarwindsAlerts = self.parse_events(events)
|
||||
for solarwindsAlert in solarwindsAlerts:
|
||||
if self.dedup.is_send(solarwindsAlert):
|
||||
self.mq.send(solarwindsAlert)
|
||||
|
||||
LOG.debug('Send heartbeat...')
|
||||
heartbeat = Heartbeat(version=Version)
|
||||
self.mq.send(heartbeat)
|
||||
|
||||
time.sleep(CONF.loop_every)
|
||||
|
||||
except (KeyboardInterrupt, SystemExit):
|
||||
self.shuttingdown = True
|
||||
|
||||
LOG.info('Shutdown request received...')
|
||||
self.running = False
|
||||
|
||||
LOG.info('Disconnecting from message broker...')
|
||||
self.mq.disconnect()
|
||||
|
||||
def parse_events(self, data):
|
||||
|
||||
LOG.debug('Parsing solarwinds events...')
|
||||
solarwindsAlerts = list()
|
||||
|
||||
for d in data:
|
||||
LOG.debug(d)
|
||||
LOG.debug(SOLAR_WINDS_SEVERITY_LEVELS[d.c7])
|
||||
|
||||
event = d.c4
|
||||
resource = '%s:%s' % (d.c2, d.c3)
|
||||
severity = SOLAR_WINDS_SEVERITY_LEVELS[d.c7]
|
||||
status = 'ack' if d.c6 == 'True' else 'open'
|
||||
group = 'Orion'
|
||||
value = ''
|
||||
text = d.c5
|
||||
environment = ['INFRA']
|
||||
service = ['Network']
|
||||
tags = None
|
||||
correlate = list()
|
||||
timeout = None
|
||||
threshold_info = None
|
||||
summary = None
|
||||
raw_data = str(d)
|
||||
create_time = datetime.datetime.strptime(d.c1[:-5]+'Z', '%Y-%m-%dT%H:%M:%S.%fZ'),
|
||||
|
||||
syslogAlert = Alert(
|
||||
resource=resource,
|
||||
event=event,
|
||||
correlate=correlate,
|
||||
group=group,
|
||||
value=value,
|
||||
severity=severity,
|
||||
environment=environment,
|
||||
service=service,
|
||||
text=text,
|
||||
event_type='solarwindsAlert',
|
||||
tags=tags,
|
||||
timeout=timeout,
|
||||
threshold_info=threshold_info,
|
||||
summary=summary,
|
||||
raw_data=raw_data,
|
||||
)
|
||||
|
||||
# suppress = syslogAlert.transform_alert(facility=facility, level=level)
|
||||
# if suppress:
|
||||
# LOG.warning('Suppressing %s.%s alert', facility, level)
|
||||
# LOG.debug('%s', syslogAlert)
|
||||
# continue
|
||||
|
||||
solarwindsAlerts.append(syslogAlert)
|
||||
|
||||
return solarwindsAlerts
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
77
alerta/solarwinds/swis.py
Normal file
77
alerta/solarwinds/swis.py
Normal file
|
@ -0,0 +1,77 @@
|
|||
|
||||
from suds.client import Client
|
||||
|
||||
from alerta.common import config
|
||||
from alerta.common import log as logging
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
CONF = config.CONF
|
||||
|
||||
SOLAR_WINDS_STATUS_LEVELS = {
|
||||
0: 'Unknown',
|
||||
1: 'Up',
|
||||
2: 'Down',
|
||||
3: 'Warning',
|
||||
14: 'Critical'
|
||||
}
|
||||
|
||||
SOLAR_WINDS_SEVERITY_LEVELS = {
|
||||
'Add': 'informational',
|
||||
'Critical': 'critical',
|
||||
'Disabled': 'warning',
|
||||
'External': 'informational',
|
||||
'Green': 'normal',
|
||||
'Red': 'critical',
|
||||
'RedAlert': 'major',
|
||||
'RedYield': 'minor',
|
||||
'Shutdown': 'warning',
|
||||
'Start': 'informational',
|
||||
'Testing': 'debug',
|
||||
'Undefined': 'informational',
|
||||
'Unknown': 'informational',
|
||||
'Unmanage': 'informational',
|
||||
'Unmanged': 'informational',
|
||||
'Unplugged': 'warning',
|
||||
'Unreachable': 'minor',
|
||||
'Warn': 'warning'
|
||||
}
|
||||
|
||||
|
||||
class SwisClient(object):
|
||||
|
||||
def __init__(self, username=None, password=None):
|
||||
|
||||
self.wsdl = 'https://%s:17778/SolarWinds/InformationService/v3?wsdl' % CONF.solarwinds_host
|
||||
LOG.debug('wsdl = %s', self.wsdl)
|
||||
self.client = Client(self.wsdl, username=username, password=password)
|
||||
self.client.set_options(port='BasicHttpBinding_InformationService')
|
||||
|
||||
self.event_id_cursor = 0
|
||||
|
||||
def get_events(self):
|
||||
|
||||
query = 'SELECT MAX(EventID) AS MaxEventID FROM Orion.Events'
|
||||
|
||||
max = self.client.service.QueryXml(query)
|
||||
last_event_id = max.queryResult.data.row.c0
|
||||
|
||||
LOG.debug('%s -> %s', self.event_id_cursor, last_event_id)
|
||||
|
||||
if last_event_id == self.event_id_cursor:
|
||||
return []
|
||||
|
||||
query = 'SELECT EventID, EventTime, NetworkNode, NetObjectID, ET.Name, Message, Acknowledged, ET.Icon ' + \
|
||||
'FROM Orion.Events E ' + \
|
||||
'INNER JOIN Orion.EventTypes AS ET ON E.EventType = ET.EventType ' + \
|
||||
'WHERE EventID > %s AND EventID <= %s ' % (self.event_id_cursor, last_event_id) + \
|
||||
'ORDER BY EventID'
|
||||
|
||||
LOG.debug('query = %s', query)
|
||||
|
||||
self.event_id_cursor = last_event_id
|
||||
x = self.client.service.QueryXml(query)
|
||||
|
||||
LOG.debug(x)
|
||||
|
||||
return x.queryResult.data.row
|
||||
|
28
bin/alert-solarwinds
Normal file
28
bin/alert-solarwinds
Normal file
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/env python
|
||||
########################################
|
||||
#
|
||||
# alert-solarwinds - Alert SolarWinds
|
||||
#
|
||||
########################################
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
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.solarwinds.daemon import SolarWindsDaemon, Version
|
||||
|
||||
LOG = logging.getLogger('alerta.solarwinds')
|
||||
CONF = config.CONF
|
||||
|
||||
if __name__ == '__main__':
|
||||
config.parse_args(sys.argv[1:], version=Version)
|
||||
logging.setup('alerta')
|
||||
solarwinds = SolarWindsDaemon('alert-solarwinds')
|
||||
solarwinds.start()
|
|
@ -4,5 +4,6 @@ Flask
|
|||
PyYAML
|
||||
pytz
|
||||
boto
|
||||
suds
|
||||
dynect
|
||||
CoilMQ
|
||||
|
|
1
setup.py
1
setup.py
|
@ -24,6 +24,7 @@ setuptools.setup(
|
|||
'bin/alert-query',
|
||||
'bin/alert-sender',
|
||||
'bin/alert-snmptrap',
|
||||
'bin/alert-solarwinds',
|
||||
'bin/alert-syslog',
|
||||
'bin/alert-urlmon',
|
||||
'bin/alerta',
|
||||
|
|
Loading…
Reference in a new issue