Skip to content

Commit

Permalink
move system default opts into each module
Browse files Browse the repository at this point in the history
  • Loading branch information
satterly committed Oct 19, 2013
1 parent af64812 commit c4d63ab
Show file tree
Hide file tree
Showing 17 changed files with 213 additions and 104 deletions.
17 changes: 13 additions & 4 deletions alerta/aws/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from alerta.common.dedup import DeDup
from alerta.common.mq import Messaging, MessageHandler

Version = '2.0.4'
Version = '2.0.5'

LOG = logging.getLogger(__name__)
CONF = config.CONF
Expand All @@ -34,10 +34,19 @@ def on_disconnected(self):


class AwsDaemon(Daemon):

def __init__(self, prog):

aws_opts = {
'fog_file': '/etc/fog/alerta.conf',
'ec2_regions': ['eu-west-1', 'us-east-1'],
'http_proxy': None,
'https_proxy': None,
}

def __init__(self, prog, **kwargs):

config.register_opts(AwsDaemon.aws_opts)

Daemon.__init__(self, prog)
Daemon.__init__(self, prog, kwargs)

self.info = {}
self.last = {}
Expand Down
10 changes: 9 additions & 1 deletion alerta/checker/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,22 @@
from alerta.common import severity_code
from alerta.common.api import ApiClient

Version = '2.0.2'
Version = '2.0.3'

LOG = logging.getLogger(__name__)
CONF = config.CONF


class CheckerClient(object):

nagios_opts = {
'nagios_plugins': '/usr/lib64/nagios/plugins',
}

def __init__(self):

config.register_opts(CheckerClient.nagios_opts)

def main(self):

if CONF.heartbeat:
Expand Down
11 changes: 9 additions & 2 deletions alerta/common/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,30 @@
from alerta.common import config
from alerta.common.utils import DateEncoder

Version = '2.0.6'
Version = '2.0.7'

LOG = logging.getLogger(__name__)
CONF = config.CONF


class ApiClient(object):

api_opts = {
'api_host': 'localhost',
'api_port': 8080,
'api_version': 'v2',
}

def __init__(self, host=None, port=None, version='v2'):

config.register_opts(ApiClient.api_opts)

self.host = host or CONF.api_host
self.port = port or CONF.api_port
self.version = version or CONF.api_version

def send(self, msg):


LOG.debug('header = %s', msg.get_header())
LOG.debug('message = %s', msg.get_body())

Expand Down
92 changes: 6 additions & 86 deletions alerta/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
CONF = Bunch() # config options can be accessed using CONF.verbose or CONF.use_syslog


def register_opts(opts):

CONF.update(opts)


def parse_args(argv, prog=None, version='unknown', cli_parser=None, daemon=True):

if prog is None:
Expand All @@ -33,13 +38,6 @@ def parse_args(argv, prog=None, version='unknown', cli_parser=None, daemon=True)

'timezone': 'Europe/London',

'api_host': 'localhost',
'api_port': 8080,
'api_version': 'v2',

'http_proxy': None,
'https_proxy': None,

'user_id': 'alerta',
'server_threads': 4,
'disable_flag': '/var/run/alerta/%s.disable' % prog,
Expand All @@ -50,89 +48,11 @@ def parse_args(argv, prog=None, version='unknown', cli_parser=None, daemon=True)
'token_limit': 20,
'token_rate': 2,

'mongo_host': 'localhost',
'mongo_port': 27017,
'mongo_database': 'monitoring',
'mongo_collection': 'alerts',
'mongo_username': 'admin',
'mongo_password': '',

'console_limit': 1000, # max number of alerts sent to console
'history_limit': -10, # show last x most recent history entries
'dashboard_dir': '/',

'stomp_host': 'localhost',
'stomp_port': 61613,

'inbound_queue': '/exchange/alerts',
'outbound_queue': '/queue/logger',
'outbound_topic': '/topic/notify',
'forward_duplicate': False,

'rabbit_host': 'localhost',
'rabbit_port': 5672,
'rabbit_use_ssl': False,
'rabbit_userid': 'guest',
'rabbit_password': 'guest',
'rabbit_virtual_host': '/',

'syslog_udp_port': 514,
'syslog_tcp_port': 514,
'syslog_facility': 'local7',

'ping_file': '/etc/alerta/alert-pinger.targets',
'ping_max_timeout': 15, # seconds
'ping_max_retries': 2,
'ping_slow_warning': 5, # ms
'ping_slow_critical': 10, # ms

'urlmon_file': '/etc/alerta/alert-urlmon.targets',
'urlmon_max_timeout': 15, # seconds
'urlmon_slow_warning': 2000, # ms
'urlmon_slow_critical': 5000, # ms

'smtp_host': 'smtp',
'smtp_port': 25,
'mail_user': '[email protected]',
'mail_list': '[email protected]',

'irc_host': 'irc',
'irc_port': 6667,
'irc_channel': '#alerts',
'irc_user': 'alerta',

'solarwinds_host': 'solarwinds',
'solarwinds_username': 'admin',
'solarwinds_password': '',
'solarwinds_group': 'websys',

'es_host': 'localhost',
'es_port': 9200,
'es_index': 'alerta-%Y.%m.%d', # NB. Kibana config must match this index

'pagerduty_endpoint': 'https://events.pagerduty.com/generic/2010-04-15/create_event.json',
'pagerduty_api_key': '',

'dynect_customer': '',
'dynect_username': '',
'dynect_password': '',

'fog_file': '/etc/fog/alerta.conf', # used by alert-aws
'ec2_regions': ['eu-west-1', 'us-east-1'],

'gmetric_host': 'localhost',
'gmetric_port': 8649,
'gmetric_protocol': 'udp',
'gmetric_spoof': '10.1.1.1:%s' % prog,

'graphite_prefix': 'alerta.%s' % socket.gethostname(),
'carbon_host': 'localhost',
'carbon_port': 2003,
'carbon_protocol': 'udp',

'statsd_host': 'localhost',
'statsd_port': 8125,

'nagios_plugins': '/usr/lib64/nagios/plugins',
}
CONF.update(SYSTEM_DEFAULTS)

Expand Down
9 changes: 9 additions & 0 deletions alerta/common/ganglia.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,17 @@ class Gmetric:
Class to send gmetric/gmond 2.X packets
"""

ganglia_opts ={
'gmetric_host': 'localhost',
'gmetric_port': 8649,
'gmetric_protocol': 'udp',
'gmetric_spoof': '10.1.1.1:%s' % prog,
}

def __init__(self, host=None, port=None, protocol=None):

config.register_opts(Gmetric.ganglia_opts)

self.host = host or CONF.gmetric_host
self.port = port or CONF.gmetric_port
self.protocol = protocol or CONF.gmetric_protocol
Expand Down
16 changes: 16 additions & 0 deletions alerta/common/graphite.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,17 @@

class Carbon(object):

carbon_opts = {
'graphite_prefix': 'alerta.%s' % socket.gethostname(),
'carbon_host': 'localhost',
'carbon_port': 2003,
'carbon_protocol': 'udp',
}

def __init__(self, host=None, port=None, protocol=None, prefix=None):

config.register_opts(Carbon.carbon_opts)

self.host = host or CONF.carbon_host
self.port = port or CONF.carbon_port
self.protocol = protocol or CONF.carbon_protocol
Expand Down Expand Up @@ -92,8 +101,15 @@ def shutdown(self):

class StatsD(object):

statsd_opts = {
'statsd_host': 'localhost',
'statsd_port': 8125,
}

def __init__(self, host=None, port=None, rate=1, prefix=None):

config.register_opts(StatsD.statsd_opts)

self.host = host or CONF.statsd_host
self.port = port or CONF.statsd_port
self.rate = rate
Expand Down
19 changes: 19 additions & 0 deletions alerta/common/mq.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,26 @@

class Messaging(object):

mq_opts = {
'stomp_host': 'localhost',
'stomp_port': 61613,

'inbound_queue': '/exchange/alerts',
'outbound_queue': '/queue/logger',
'outbound_topic': '/topic/notify',

'rabbit_host': 'localhost',
'rabbit_port': 5672,
'rabbit_use_ssl': False,
'rabbit_userid': 'guest',
'rabbit_password': 'guest',
'rabbit_virtual_host': '/',
}

def __init__(self):

config.register_opts(Messaging.mq_opts)

logging.setup('stomp.py')

def connect(self, callback=None, wait=False):
Expand Down
14 changes: 11 additions & 3 deletions alerta/dynect/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from alerta.common.mq import Messaging, MessageHandler
from alerta.common.dedup import DeDup

Version = '2.0.4'
Version = '2.0.5'

LOG = logging.getLogger(__name__)
CONF = config.CONF
Expand All @@ -32,9 +32,17 @@ def on_disconnected(self):

class DynectDaemon(Daemon):

def __init__(self, prog):
dynect_opts = {
'dynect_customer': '',
'dynect_username': '',
'dynect_password': '',
}

Daemon.__init__(self, prog)
def __init__(self, prog, **kwargs):

config.register_opts(DynectDaemon.dynect_opts)

Daemon.__init__(self, prog, kwargs)

self.info = {}
self.last_info = {}
Expand Down
15 changes: 14 additions & 1 deletion alerta/ircbot/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from alerta.common.mq import Messaging, MessageHandler
from alerta.common.tokens import LeakyBucket

Version = '2.0.3'
Version = '2.0.4'

LOG = logging.getLogger(__name__)
CONF = config.CONF
Expand Down Expand Up @@ -123,6 +123,19 @@ def on_disconnected(self):

class IrcbotDaemon(Daemon):

ircbot_opts = {
'irc_host': 'irc',
'irc_port': 6667,
'irc_channel': '#alerts',
'irc_user': 'alerta',
}

def __init__(self, prog, **kwargs):

config.register_opts(IrcbotDaemon.ircbot_opts)

Daemon.__init__(self, prog, kwargs)

def run(self):

self.running = True
Expand Down
14 changes: 13 additions & 1 deletion alerta/logger/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from alerta.common.heartbeat import Heartbeat
from alerta.common.utils import DateEncoder

Version = '2.0.2'
Version = '2.0.3'

LOG = logging.getLogger(__name__)
CONF = config.CONF
Expand Down Expand Up @@ -76,6 +76,18 @@ class LoggerDaemon(Daemon):
Index alerts in ElasticSearch using Logstash format so that logstash GUI and/or Kibana can be used as front-ends
"""

logger_opts = {
'es_host': 'localhost',
'es_port': 9200,
'es_index': 'alerta-%Y.%m.%d', # NB. Kibana config must match this index
}

def __init__(self, prog, **kwargs):

config.register_opts(LoggerDaemon.logger_opts)

Daemon.__init__(self, prog, kwargs)

def run(self):

self.running = True
Expand Down
15 changes: 14 additions & 1 deletion alerta/mailer/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from alerta.common.mail import Mailer
from alerta.common.tokens import LeakyBucket

Version = '2.0.4'
Version = '2.0.5'

LOG = logging.getLogger(__name__)
CONF = config.CONF
Expand Down Expand Up @@ -68,6 +68,19 @@ def on_disconnected(self):

class MailerDaemon(Daemon):

mailer_opt = {
'smtp_host': 'smtp',
'smtp_port': 25,
'mail_user': '[email protected]',
'mail_list': '[email protected]',
}

def __init__(self, prog, **kwargs):

config.register_opts(MailerDaemon.mailer_opt)

Daemon.__init__(self, prog, kwargs)

def run(self):

self.running = True
Expand Down
Loading

0 comments on commit c4d63ab

Please sign in to comment.