Beispiel #1
0
def delete_monitor(id=None, name=None):
    '''Delete the specified monitor
    
    If both name and id are given, prefer id'''
    if id is None:
        # get the ID based on the name
        monitor_list = [mon for mon in get_monitors()
            if mon.get_monitor_info()['name'] == name]
        monitor = monitor_list[0] # TODO handle case where len != 1
    else:
        monitor = CustomMonitor.fetch(monitor_id=id)
    monitor.delete_monitor()
Beispiel #2
0
def delete_monitor(id=None, name=None):
    '''Delete the specified monitor
    
    If both name and id are given, prefer id'''
    if id is None:
        # get the ID based on the name
        monitor_list = [
            mon for mon in get_monitors()
            if mon.get_monitor_info()['name'] == name
        ]
        monitor = monitor_list[0]  # TODO handle case where len != 1
    else:
        monitor = CustomMonitor.fetch(monitor_id=id)
    monitor.delete_monitor()
def writer_init():
    global sandbox, debug, apikey, secretkey, monitors

    # last values and timestamps must be shared across collectd threads
    # collectd will pass this shared object into write on all calls
    # all accessess to this data should be protected by threading.Lock

    shared_data = {'monitors': dict(), 'lock': threading.Lock()}

    if sandbox:
        Monitis.sandbox = True
        os.environ['MONITIS_SANDBOX_APIKEY'] = apikey
        os.environ['MONITIS_SANDBOX_SECRETKEY'] = secretkey
    else:
        Monitis.sandbox = False
        os.environ['MONITIS_APIKEY'] = apikey
        os.environ['MONITIS_SECRETKEY'] = secretkey

    if debug:
        Monitis.debug = True
    else:
        Monitis.debug = False

    for monitor_name in monitors.keys():
        monitors[monitor_name]['monitis'] = CustomMonitor.fetch(
            monitor_id=monitors[monitor_name]['id'])

    # hold lock while initializing shared_data
    with shared_data['lock']:
        for monitor_name in monitors.keys():
            shared_data['monitors'][monitor_name] = {
                'last_value': None,
                'last_time': None
            }

    collectd.register_write(write, data=shared_data)
Beispiel #4
0
 def test_fetch(self):
     '''Test CustomMonitor.fetch()'''
     mon = CustomMonitor.fetch(monitor_id=self.cm.monitor_id)
     assert_equal(mon.monitor_id, self.cm.monitor_id)