コード例 #1
0
def add_result():
    """add_result() -
     adds results to a Monitis monitor define by id save locally. 
    """    
    time, temp = read_data()
    cm = CustomMonitor(monitor_id=read_id())
    cm.add_result(temperature=temp)
コード例 #2
0
ファイル: monitors.py プロジェクト: SeanYa/Python-SDK
def create_monitor(name,aws_namespace,statistics,results):
    '''Create a custom monitor by using data from a result
    
    The monitor itself is has the given name, with each '''
    
    # identify all of the names in result
    # only need the first result, even if more than one is passed in
    
    # map the values from a AWS API result:
        # prefix+results[0]['statistic'] -> name and displayname
        # aws_namespace -> tag
        # results[0][Unit] -> uom
        # float -> datatype (since we won't know which can be ints)
    
    # create one monitor a result param per statistic in the result
    # for each statistic, also get the associated unit
    base_uom = results[0]['Unit']
    result_params = list()
    for statistic in statistics:
        # treat SampleCount differently, as the units don't apply
        if statistic is 'SampleCount':
            uom = 'Count'
            datatype = DataType('integer')
        else:
            uom = base_uom
            datatype = DataType('float')
        result_params.append(
            ResultParams(statistic, statistic, uom, datatype))
        # need name, tag, ResultParam
    CustomMonitor.add_monitor(name=name, tag=aws_namespace, *result_params)
コード例 #3
0
ファイル: monitors.py プロジェクト: kaptainkommie/Python-SDK
def create_monitor(name, aws_namespace, statistics, results):
    '''Create a custom monitor by using data from a result
    
    The monitor itself is has the given name, with each '''

    # identify all of the names in result
    # only need the first result, even if more than one is passed in

    # map the values from a AWS API result:
    # prefix+results[0]['statistic'] -> name and displayname
    # aws_namespace -> tag
    # results[0][Unit] -> uom
    # float -> datatype (since we won't know which can be ints)

    # create one monitor a result param per statistic in the result
    # for each statistic, also get the associated unit
    base_uom = results[0]['Unit']
    result_params = list()
    for statistic in statistics:
        # treat SampleCount differently, as the units don't apply
        if statistic is 'SampleCount':
            uom = 'Count'
            datatype = DataType('integer')
        else:
            uom = base_uom
            datatype = DataType('float')
        result_params.append(ResultParams(statistic, statistic, uom, datatype))
        # need name, tag, ResultParam
    CustomMonitor.add_monitor(name=name, tag=aws_namespace, *result_params)
コード例 #4
0
def update_monitor(id):
    '''Update monitor <id> with the values from netstat'''
    
    packet_count = call_netstat()
    print ', '.join([
        packet_count['tcp']['tx'], packet_count['tcp']['rx'],
        packet_count['udp']['tx'], packet_count['udp']['rx']])
    cm = CustomMonitor(monitor_id=id)
    cm.add_result(
        tcp_packets_in=packet_count['tcp']['rx'], 
        tcp_packets_out=packet_count['tcp']['tx'],
        udp_packets_in=packet_count['udp']['rx'], 
        udp_packets_out=packet_count['udp']['tx'])
コード例 #5
0
ファイル: test_custom.py プロジェクト: SeanYa/Python-SDK
 def setUpClass(self):
     # Turn on API debugging
     Monitis.debug = True
     # Monitis.sandbox = True
     
     self.result_params = ResultParams('foo',
                                'Foo Rate',
                                'foo/s', 
                                DataType('integer'))
     monitor_params = MonitorParams('bar',
                                   '',
                                   '5',
                                   DataType('integer'),
                                   'false')
     ARParams = AdditionalResultParams ('bar',
                                        'Bar Rate',
                                        'bar/s',
                                        DataType('integer'))
     
     self.cm = CustomMonitor.add_monitor(self.result_params,
                                        monitor_params,
                                        ARParams,
                                        name="test",
                                        tag='testMonitor'
                                        )
コード例 #6
0
ファイル: test_custom.py プロジェクト: SeanYa/Python-SDK
 def test_get_monitors(self):
     mon = CustomMonitor.add_monitor(
         self.result_params,name='gmtest',tag='gmtesttag')
     mon_list = get_monitors(tag='gmtesttag',m_type='custom')
     mon.delete_monitor()
     assert_equal(len(mon_list), 1)
     assert_equal(mon_list[0].tag, 'gmtesttag')
コード例 #7
0
ファイル: monitors.py プロジェクト: SeanYa/Python-SDK
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()
コード例 #8
0
ファイル: monitors.py プロジェクト: kaptainkommie/Python-SDK
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()
コード例 #9
0
def first_time():
    """first_time() -
     connects to Monitis and sets new monitor mesuring temprature up.
    """
    rp = ResultParams(
        'temperature',
        'Temperature in',
        'C',
        DataType('float'))
    cm = CustomMonitor.add_monitor(
        rp,
        name='temperature monitor',
        tag='enviromental')
    return cm.get_monitor_info()['id']
コード例 #10
0
def create_monitor(name=None):
    params1 = ResultParams(
        'tcp_packets_in','TCP Packets In','pkts/s', DataType('integer'))
    params2 = ResultParams(
        'tcp_packets_out','TCP Packets Out','pkts/s', DataType('integer'))
    params3 = ResultParams(
        'udp_packets_in','UDP Packets In','pkts/s', DataType('integer'))
    params4 = ResultParams(
        'udp_packets_out','UDP Packets Out','pkts/s', DataType('integer'))
    try:
        cm = CustomMonitor.add_monitor(
            params1, params2, params3, params4, name=name, tag='netstat')
    except MonitisError, err:
        raise Usage(err)
コード例 #11
0
    def setUp(self):
        # need a custom monitor for the test page module
        self.temp_str = 'test_' + b2a_hex(urandom(4)).upper()
        rp = ResultParams('t', 'Test', 'test', DataType('integer'))
        cm = CustomMonitor.add_monitor(rp, name=self.temp_str, tag='test')
        self.monitor_id = cm.monitor_id
        self.custom = cm

        # a contact or contact group is required
        test_email = 'test' + self.temp_str + '@test.com'
        test_contact = add_contact(first_name='Test',
                                   last_name='User',
                                   account=test_email,
                                   contact_type=1,
                                   timezone=-300,
                                   group='TestGroup_' + self.temp_str)
        self.contact_id = int(test_contact['data']['contactId'])

        # create a notification based on that custom monitor
        monitor_id = self.monitor_id
        monitor_type = 'custom'
        period = 'always'
        contact_id = self.contact_id
        notify_backup = 0
        continuous_alerts = 0
        failure_count = 1
        param_name = 't'
        param_value = '0'
        comparing_method = 'greater'

        self.test_notification = add_notification_rule(
            monitor_id=monitor_id,
            monitor_type=monitor_type,
            period=period,
            contact_id=contact_id,
            notify_backup=notify_backup,
            continuous_alerts=continuous_alerts,
            failure_count=failure_count,
            param_name=param_name,
            param_value=param_value,
            comparing_method=comparing_method)
コード例 #12
0
    def setUp(self):
        # need a custom monitor for the test page module
        self.temp_str = 'test_' + b2a_hex(urandom(4)).upper()
        rp = ResultParams('t', 'Test', 'test', DataType('integer'))
        cm = CustomMonitor.add_monitor(rp, name=self.temp_str, tag='test')
        self.monitor_id = cm.monitor_id
        self.custom = cm

        # a contact or contact group is required
        test_email = 'test' + self.temp_str + '@test.com'
        test_contact = add_contact(first_name='Test',
                                   last_name='User',
                                   account=test_email,
                                   contact_type=1,
                                   timezone=-300,
                                   group='TestGroup_' + self.temp_str)
        self.contact_id = int(test_contact['data']['contactId'])

        # create a notification based on that custom monitor
        monitor_id = self.monitor_id
        monitor_type = 'custom'
        period = 'always'
        contact_id = self.contact_id
        notify_backup = 0
        continuous_alerts = 0
        failure_count = 1
        param_name = 't'
        param_value = '0'
        comparing_method = 'greater'

        self.test_notification = add_notification_rule(
            monitor_id=monitor_id,
            monitor_type=monitor_type,
            period=period,
            contact_id=contact_id,
            notify_backup=notify_backup,
            continuous_alerts=continuous_alerts,
            failure_count=failure_count,
            param_name=param_name,
            param_value=param_value,
            comparing_method=comparing_method)
コード例 #13
0
ファイル: test_layout.py プロジェクト: SeanYa/Python-SDK
    def setUp(self):
        Monitis.sandbox = False
        Monitis.debug = True

        self.test_page_ids = []
        # test page
        self.temp_str = 'test_' + b2a_hex(urandom(4)).upper()
        self.test_page_name = self.temp_str
        result = monitis.layout.add_page(title=self.test_page_name)
        self.test_page_ids.append(result['data']['pageId'])

        # need a custom monitor for the test page module
        rp = ResultParams('t', 'Test', 'test', DataType('integer'))
        cm = CustomMonitor.add_monitor(rp, name=self.temp_str, tag='test')
        self.custom = cm

        res = monitis.layout.add_page_module(module_name='CustomMonitor',
                                             page_id=self.test_page_ids[0],
                                             column=1,
                                             row=2,
                                             data_module_id=self.custom.monitor_id)
        self.test_page_module_id = res['data']['pageModuleId']
コード例 #14
0
    def setUp(self):
        Monitis.sandbox = False
        Monitis.debug = True

        self.test_page_ids = []
        # test page
        self.temp_str = 'test_' + b2a_hex(urandom(4)).upper()
        self.test_page_name = self.temp_str
        result = monitis.layout.add_page(title=self.test_page_name)
        self.test_page_ids.append(result['data']['pageId'])

        # need a custom monitor for the test page module
        rp = ResultParams('t', 'Test', 'test', DataType('integer'))
        cm = CustomMonitor.add_monitor(rp, name=self.temp_str, tag='test')
        self.custom = cm

        res = monitis.layout.add_page_module(
            module_name='CustomMonitor',
            page_id=self.test_page_ids[0],
            column=1,
            row=2,
            data_module_id=self.custom.monitor_id)
        self.test_page_module_id = res['data']['pageModuleId']
コード例 #15
0
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)
コード例 #16
0
ファイル: test_custom.py プロジェクト: SeanYa/Python-SDK
 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)
コード例 #17
0
def delete_monitor(id):
    try:
        cm = CustomMonitor(monitor_id=id)
        cm.delete_monitor()
    except MonitisError, err:
        raise Usage(err)
コード例 #18
0
from subprocess import Popen, PIPE
from re import findall
from datetime import datetime

from monitis.monitors.custom import CustomMonitor, get_monitors
from monitis.monitors.params import ResultParams, DataType
from monitis.api import Monitis

# Use the Monitis sandbox, sandbox.monitis.com
Monitis.sandbox = True

# create the monitor
rp = ResultParams(
    'tcp_packets_in','TCP Packets In','pkts/s', DataType('integer'))
cm = CustomMonitor.add_monitor(rp, name='netstat monitor', tag='netstat')
print "Created monitor: %s" % cm.monitor_id

# get the data from netstat
subproc = Popen(
    'netstat -s -p tcp | grep "packets received$"', shell=True, stdout=PIPE)
(netstat_out, netstat_err) = subproc.communicate()
count = findall('(\d+) packets received', netstat_out)[0]
print "Netstat count: %s" % count

# send the result to the Monitis sandbox
cm.add_result(tcp_packets_in=count)
print "Posted result"

# retrieve the results from the monitor and print it to verify that it worked
today = datetime.utcnow()
コード例 #19
0
from subprocess import Popen, PIPE
from re import findall
from datetime import datetime

from monitis.monitors.custom import CustomMonitor, get_monitors
from monitis.monitors.params import ResultParams, DataType
from monitis.api import Monitis

# Use the Monitis sandbox, sandbox.monitis.com
Monitis.sandbox = True

# create the monitor
rp = ResultParams('tcp_packets_in', 'TCP Packets In', 'pkts/s',
                  DataType('integer'))
cm = CustomMonitor.add_monitor(rp, name='netstat monitor', tag='netstat')
print "Created monitor: %s" % cm.monitor_id

# get the data from netstat
subproc = Popen('netstat -s -p tcp | grep "packets received$"',
                shell=True,
                stdout=PIPE)
(netstat_out, netstat_err) = subproc.communicate()
count = findall('(\d+) packets received', netstat_out)[0]
print "Netstat count: %s" % count

# send the result to the Monitis sandbox
cm.add_result(tcp_packets_in=count)
print "Posted result"

# retrieve the results from the monitor and print it to verify that it worked