Exemple #1
0
    def run(self):

        self.running = True

        self.queue = Queue.Queue()
        self.api = self.api = ApiClient(endpoint=settings.ENDPOINT,
                                        key=settings.API_KEY)

        # Start worker threads
        LOG.debug('Starting %s worker threads...', SERVER_THREADS)
        for i in range(SERVER_THREADS):
            w = WorkerThread(self.queue, self.api)
            try:
                w.start()
            except Exception, e:
                LOG.error('Worker thread #%s did not start: %s', i, e)
                continue
            LOG.info('Started worker thread: %s', w.getName())
Exemple #2
0
    def __init__(self):

        self.api = ApiClient()

        try:
            connection = boto.sqs.connect_to_region(
                AWS_REGION,
                aws_access_key_id=AWS_ACCESS_KEY_ID,
                aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
        except boto.exception.SQSError as e:
            LOG.error('SQS API call failed: %s', e)
            sys.exit(1)

        try:
            self.sqs = connection.create_queue(AWS_SQS_QUEUE)
            self.sqs.set_message_class(RawMessage)
        except boto.exception.SQSError as e:
            LOG.error('SQS queue error: %s', e)
            sys.exit(1)
Exemple #3
0
    def run(self):

        endpoint = os.environ.get('ALERTA_ENDPOINT', 'http://localhost:8080')
        key = os.environ.get('ALERTA_API_KEY', None)

        self.api = ApiClient(endpoint=endpoint, key=key)

        data = sys.stdin.read()
        LOG.info('snmptrapd -> %r', data)
        data = unicode(data, 'utf-8', errors='ignore')
        LOG.debug('unicoded -> %s', data)

        snmptrapAlert = SnmpTrapHandler.parse_snmptrap(data)

        if snmptrapAlert:
            try:
                self.api.send(snmptrapAlert)
            except Exception, e:
                LOG.warning('Failed to send alert: %s', e)
Exemple #4
0
import argparse
import threading
from os.path import dirname, basename, join

import urllib3
import requests
from packaging.version import Version
from alerta.api import ApiClient
from alerta.alert import Alert

import utils

urllib3.disable_warnings()

alerta_endpoint = 'http://localhost:8090'
api = ApiClient(endpoint=alerta_endpoint)
DRY_RUN = False

#
# alert monitoring functions, kind of wrapping functions in utils
#


def alert_volume_not_existing(path):
    """
    Alert if a volume does not exist, delete previous alert if it does.
    
    Command-line alternative (replace path argument):

        alerta send -r localhost -e VolumeUnavailable -E Localhost \
            -S Filesystem -s minor -t "Volume not available." -v <path>
Exemple #5
0
    def __init__(self):

        self.api = ApiClient()
Exemple #6
0
    def set(self, endpoint, key):

        self.api = ApiClient(endpoint=endpoint, key=key)
Exemple #7
0
)

# In[ ]:

get_ipython().system(
    u' cd $ALERTA_TEST_DIR && ./miniconda2/bin/alerta     --endpoint-url "http://localhost:8090"     delete'
)

# ### Same Thing, Python style

# In[ ]:

from alerta.api import ApiClient
from alerta.alert import Alert

api = ApiClient(endpoint='http://localhost:8090')
alert = Alert(resource='localhost',
              event='VolUnavailable',
              service=['Filesystem'],
              environment='Production',
              value='ERROR',
              severity='minor')
res = api.send(alert)

# ## Custom Alerts

# ### Remember, you can do amazing stuff…

# In[ ]:

import utils
Exemple #8
0
            sys.exit(2)
        LOG.info('Listening on syslog port %s/udp' % SYSLOG_UDP_PORT)

        LOG.info('Starting TCP listener...')
        # Set up syslog TCP listener
        try:
            tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            tcp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            tcp.bind(('', SYSLOG_TCP_PORT))
            tcp.listen(5)
        except socket.error, e:
            LOG.error('Syslog TCP error: %s', e)
            sys.exit(2)
        LOG.info('Listening on syslog port %s/tcp' % SYSLOG_TCP_PORT)

        self.api = self.api = ApiClient(endpoint=settings.ENDPOINT, key=settings.API_KEY)

        count = 0
        while not self.shuttingdown:
            try:
                LOG.debug('Waiting for syslog messages...')
                ip, op, rdy = select.select([udp, tcp], [], [], LOOP_EVERY)
                if ip:
                    for i in ip:
                        if i == udp:
                            data, addr = udp.recvfrom(4096)
                            data = unicode(data, 'utf-8', errors='ignore')
                            LOG.debug('Syslog UDP data received from %s: %s', addr, data)
                        if i == tcp:
                            client, addr = tcp.accept()
                            data = client.recv(4096)