def test_MonitisError(self): '''Test calls to the API that raise a MonitisError''' try: get(action='secretkey',apikey='bad_api_key') except MonitisError, error: assert_equal(str(error), 'MonitisError(API Error: {"error":"Authentication failure"})')
def test_MonitisError(self): '''Test calls to the API that raise a MonitisError''' try: get(action='secretkey', apikey='bad_api_key') except MonitisError, error: assert_equal( str(error), 'MonitisError(API Error: {"error":"Authentication failure"})')
def sub_accounts(**kwargs): ''' The subaccounts associated with the given API key Results resturned as a JSON structure ''' return get(action='subAccounts', **kwargs)
def get_notification_rules(**kwargs): ''' Get list of existing notification rules for the specified monitor ''' required = ['monitorId', 'monitorType'] optional = [] get_args = validate_kwargs(required, optional, **kwargs) return get(action='getNotificationRules', **get_args)
def secretkey(apikey=None): ''' The secret key associated with the given API key ''' if apikey is None: apikey = resolve_apikey() return get(action='secretkey', apikey=apikey)['secretkey']
def get_recent_alerts(**kwargs): ''' Get recent alerts history Start date and end date are in miliseconds since the Epoch''' required = [] optional = ['timezone', 'startDate', 'endDate'] post_args = validate_kwargs(required, optional, **kwargs) return get(action='recentAlerts', **post_args)
def transaction_test_result(**kwargs): ''' Get results for the specified Transaction or Full Page Load monitor ''' required = ['monitorId', 'year', 'month', 'day'] optional = ['locationIds', 'timezone'] req_args = validate_kwargs(required, optional, **kwargs) return get(action='transactionTestResult', **req_args)
def apikey(username, password): ''' The API key associated with the given username and password ''' password_hash = md5() password_hash.update(password) password_digest = password_hash.hexdigest() result = get(action='apikey', userName=username, password=password_digest) return result['apikey']
def transaction_snapshot(**kwargs): ''' Get last results of user's Transaction monitors ''' required = [] optional = ['locationIds'] req_args = validate_kwargs(required, optional, **kwargs) location_ids = req_args.get('locationIds', None) if isinstance(location_ids, list): req_args['locationIds'] = ','.join(map(str,location_ids)) return get(action='transactionSnapshot', **req_args)
def cloud_instances(**kwargs): ''' Get a user's cloud instances Parameters: timezoneoffset - offset relative to GMT, in minutes ''' required = [] optional = ['timezoneoffset'] req_args = validate_kwargs(required, optional, **kwargs) return get(action='cloudInstances', **req_args)
def internal_result(**kwargs): ''' Helper function to get results for internal monitors This function does not directly map to any specific action in the Monitis API. Rather, it is a helper, and requires that the calling function supply the action, in addition to the agent ID. ''' required = ['monitorId', 'day', 'month', 'year', 'action'] optional = ['timezone'] req_args = validate_kwargs(required, optional, **kwargs) return get(**req_args)
def internal_result(**kwargs): """ Helper function to get results for internal monitors This function does not directly map to any specific action in the Monitis API. Rather, it is a helper, and requires that the calling function supply the action, in addition to the agent ID. """ required = ["monitorId", "day", "month", "year", "action"] optional = ["timezone"] req_args = validate_kwargs(required, optional, **kwargs) return get(**req_args)
def agent_monitors(**kwargs): """ Helper function to get agent monitors This function does not directly map to any specific action in the Monitis API. Rather, it is a helper, and requires that the calling function supply the action, in addition to the agent ID. """ required = ["agentId", "action"] optional = [] req_args = validate_kwargs(required, optional, **kwargs) return get(**req_args)
def visitor_tracking_info(**kwargs): ''' get information about the specified Visitor Tracker Results are a list, but the order may differ from the docs [siteId, url, name, monitorId], though it isn't entirely clear. ''' required = ['siteId'] optional = [] req_args = validate_kwargs(required, optional, **kwargs) return get(action='visitorTrackingInfo', **req_args)
def full_page_load_test_result(**kwargs): ''' Get results for the specified Full Page Load monitor ''' required = ['monitorId', 'year', 'month', 'day'] optional = ['locationIds', 'timezone'] req_args = validate_kwargs(required, optional, **kwargs) location_ids = req_args.get('locationIds', None) if isinstance(location_ids, list): req_args['locationIds'] = ','.join(location_ids) return get(action='fullPageLoadTestResult', **req_args)
def agent_monitors(**kwargs): ''' Helper function to get agent monitors This function does not directly map to any specific action in the Monitis API. Rather, it is a helper, and requires that the calling function supply the action, in addition to the agent ID. ''' required = ['agentId', 'action'] optional = [] req_args = validate_kwargs(required, optional, **kwargs) return get(**req_args)
def tests_last_values(**kwargs): ''' Get the last results of a user's external monitors ''' required = [] optional = ['locationIds'] req_args = validate_kwargs(required, optional, **kwargs) # locationIds may be a list location_ids = req_args.get('locationIds') if type(location_ids) is list: req_args['locationIds'] = ','.join(location_ids) return get(action='testsLastValues', **req_args)
def testresult(**kwargs): ''' Get results of the specified External monitor ''' required = ['testId', 'day', 'month', 'year'] optional = ['locationIds', 'timezone'] req_args = validate_kwargs(required, optional, **kwargs) # locationIds may be a list location_ids = req_args.get('locationIds') if type(location_ids) is list: req_args['locationIds'] = ','.join(location_ids) return get(action='testresult', **req_args)
def auth_token(apikey=None, secretkey=None): ''' Generate an auth token If the apikey and/or secretkey are not specified as parameters, then they will be resolved, if possible. ''' if apikey is None: apikey = resolve_apikey() if secretkey is None: secretkey = resolve_secretkey() return get(action='authToken', apikey=apikey, secretkey=secretkey)['authToken']
def internal_monitors(**kwargs): """ Get a user's internal monitors Monitors returned can be filtered by type, such as: - memory - load - drive - process - cpu - agentHttpTest - agentPingTest """ required = [] optional = ["types", "tag", "tagRegExp"] req_args = validate_kwargs(required, optional, **kwargs) types = req_args.get("types", None) if isinstance(types, list): req_args["types"] = ",".join(types) return get(action="internalMonitors", **req_args)
def internal_monitors(**kwargs): ''' Get a user's internal monitors Monitors returned can be filtered by type, such as: - memory - load - drive - process - cpu - agentHttpTest - agentPingTest ''' required = [] optional = ['types', 'tag', 'tagRegExp'] req_args = validate_kwargs(required, optional, **kwargs) types = req_args.get('types', None) if isinstance(types, list): req_args['types'] = ','.join(types) return get(action='internalMonitors', **req_args)
def setUp(self): # Monitis.sandbox = True Monitis.debug = True [monitis.user.delete_sub_account(x['id']) for x in monitis.user.sub_accounts() if x['account'].endswith('@test.com')] first_name = 'Test' last_name = 'Account' email = '*****@*****.**' password = '******' group = 'testgroup' ret = monitis.user.add_sub_account(first_name, last_name, email, password, group) self.test_account_id = ret['data']['userId'] page_title = get(action='pages')[0]['title'] res = monitis.user.add_sub_account_pages(user_id=self.test_account_id, pages=[page_title])
def tagtests(**kwargs): ''' Get external monitors for the specified tag ''' required = ['tag'] optional = [] req_args = validate_kwargs(required, optional, **kwargs) return get(action='tagtests', **req_args)
def locations(**kwargs): ''' Get all of the locations for the user's external monitors ''' required = [] optional = [] req_args = validate_kwargs(required, optional, **kwargs) return get(action='locations', **req_args)
def testinfo(**kwargs): ''' Get information for the specified external monitor ''' required = ['testId'] optional = ['timezone'] req_args = validate_kwargs(required, optional, **kwargs) return get(action='testinfo', **req_args)
def tests(**kwargs): ''' Get all external monitors for the user ''' required = [] optional = [] req_args = validate_kwargs(required, optional, **kwargs) return get(action='tests', **req_args)
def test_delete_sub_account_pages(self): page_title = get(action='pages')[0]['title'] res = monitis.user.delete_sub_account_pages(user_id=self.test_account_id, pages=[page_title]) assert_equal(res['status'], 'ok')
def agent_snapshot(**kwargs): ''' Get last results for all monitors of the specified agent ''' required = ['agentKey'] optional = ['timezone'] req_args = validate_kwargs(required, optional, **kwargs) return get(action='agentSnapshot', **req_args)
def all_agents_snapshot(**kwargs): ''' Get last results for user's internal monitors ''' required = ['platform'] optional = ['timezone', 'tag'] req_args = validate_kwargs(required, optional, **kwargs) return get(action='allAgentsSnapshot', **req_args)
def agent_info(**kwargs): ''' Get information regarding the specified agent ''' required = ['agentId'] optional = ['loadTests'] req_args = validate_kwargs(required, optional, **kwargs) return get(action='agentInfo', **req_args)
def agents(**kwargs): ''' Get a user's agents ''' required = [] optional = ['keyRegExp'] req_args = validate_kwargs(required, optional, **kwargs) return get(action='agents', **req_args)
def _custom_get(**kwargs): '''HTTP GET using URL for customMonitor API''' return get(_url=_api_url(), **kwargs)
def visitor_tracking_tests(**kwargs): ''' Get a user's visitor trackers ''' required = [] optional = [] req_args = validate_kwargs(required, optional, **kwargs) return get(action='visitorTrackingTests', **req_args)
def full_page_load_locations(**kwargs): ''' Get all locations for full page load monitors ''' required = [] optional = [] req_args = validate_kwargs(required, optional, **kwargs) return get(action='fullPageLoadLocations', **req_args)
def visitor_tracking_results(**kwargs): ''' Get results of the specified Visitor Tracker ''' required = ['siteId', 'year', 'month', 'day'] optional = ['timezoneoffset'] req_args = validate_kwargs(required, optional, **kwargs) return get(action='visitorTrackingResults', **req_args)
def get_contact_groups(): ''' Get all contact groups for the user ''' return get(action='contactGroupList')