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)
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)
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')
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' )
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']
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)
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)
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']
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']
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
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()