def update_monitor(name, aws_namespace, statistics, results): '''Update the monitor with the specified results''' # keep a map of names to ids, to avoid unnecessary lookups # if update is going to be called more than once per run # or, persist the map count = 0 # if no existing map, then find the existing monitor that matches monitors = [ mon for mon in list_monitors(aws_namespace) if name == mon.get_monitor_info()['name'] ] # TODO handle case where len(monitors) != 1 if len(monitors) < 1: raise Usage("No matching monitors found") elif len(monitors) > 1: raise Usage("More than one monitor found with name %s") % name else: monitor = monitors[0] # post all of the results we found for result in results: result_checktime = checktime(result['Timestamp']) result_params = dict() for statistic in statistics: result_params[statistic] = result[statistic] count += 1 ct = monitor.add_result(result_checktime, results=result_params) return count
def update_monitor(name,aws_namespace,statistics,results): '''Update the monitor with the specified results''' # keep a map of names to ids, to avoid unnecessary lookups # if update is going to be called more than once per run # or, persist the map count = 0 # if no existing map, then find the existing monitor that matches monitors = [mon for mon in list_monitors(aws_namespace) if name == mon.get_monitor_info()['name']] # TODO handle case where len(monitors) != 1 if len(monitors) < 1: raise Usage("No matching monitors found") elif len(monitors) > 1: raise Usage("More than one monitor found with name %s") % name else: monitor = monitors[0] # post all of the results we found for result in results: result_checktime = checktime(result['Timestamp']) result_params = dict() for statistic in statistics: result_params[statistic] = result[statistic] count += 1 ct = monitor.add_result(result_checktime, results=result_params) return count
def test_checktime(self): # delta between checktime and the current time should be < 5 sec assert abs(int(checktime()) - int(str(int(time())) + "000")) < 5000