def main(): # May be able to delete this test because the find_process check should # validate the notification engine present. if not utils.ensure_has_notification_engine(): return 1 utils.setup_cli() # parse the command line arguments cmd_args = parse_commandline_args() if not set_config(cmd_args.config): return 1 print('*****VERIFYING HOST ENVIRONMENT*****') if find_processes(): print('*****BEGIN TEST*****') complete, msg = smoke_test() if not complete: print('*****TEST FAILED*****', file=sys.stderr) print(msg, file=sys.stderr) return 1 else: return 1 cleanup(config['notification']['name'], config['alarm']['name']) print('*****TEST COMPLETE*****') return 0
def main(): if len(sys.argv) == 1: print('usage: %s count [alarm-id]' % sys.argv[0], file=sys.stderr) return 1 if not utils.ensure_has_notification_engine(): return 1 mon_client = utils.create_mon_client() num_cycles = int(sys.argv[1]) alarm_name = 'notification_cycleTest' alarm_json = alarm.find_alarm_byname(mon_client, alarm_name) if alarm_json is not None: alarm_id = alarm_json['id'] else: existing = notification.find_by_name(mon_client, alarm_name) if existing is not None: notification_id = existing['id'] else: notification_id = notification.create(mon_client, alarm_name, "root@localhost") alarm_id = alarm.create(mon_client, alarm_name, None, 'max(cc) > 100', notification_id, notification_id, notification_id) user = '******' start_time = time.time() initial_state = alarm.get_state(mon_client, alarm_id) state = initial_state existing_notifications = utils.find_notifications(alarm_id, user) notifications_sent = num_cycles * 2 for _ in range(0, notifications_sent): if state == 'OK': state = 'ALARM' else: state = 'OK' if not alarm.set_state(mon_client, alarm_id, state): return 1 print("Took %d seconds to send %d alarm state changes" % ((time.time() - start_time), num_cycles * 2)) for i in range(0, 30): notifications = utils.find_notifications(alarm_id, user) notifications_found = len(notifications) - len(existing_notifications) if notifications_found >= notifications_sent: break print('Found %d of %d expected notifications so far' % (notifications_found, notifications_sent)) time.sleep(1) if notifications_found < notifications_sent: print('Expected %d notifications but found %d' % (notifications_sent, notifications_found), file=sys.stderr) return 1 print('Took %d seconds for notifications to fully arrive' % i) result = 0 return result
def main(): if not utils.ensure_has_notification_engine(): return 1 # Delete notification for OK.Cycle OK, ALARM, UNDETERMINED # Ensure proper notifications got written for ALARM, UNDETERMINED states = ['OK', 'ALARM', 'UNDETERMINED'] mon_client = utils.create_mon_client() try: # Create 3 notifications with different emails, root, kafka, # and monasca-agent email1 = "root" email2 = "kafka" email3 = "monasca-agent" notification_id_1 = find_or_create_notification(mon_client, email1, email1 + "@localhost") notification_id_2 = find_or_create_notification(mon_client, email2, email2 + "@localhost") notification_id_3 = find_or_create_notification(mon_client, email3, email3 + "@localhost") # Create an alarm. Cycle OK, ALARM, UNDETERMINED, alarm_name = "Test Notifications-" + str(os.getpid()) expr = 'max(not_real_metric{}) > 10' alarm_id = alarm.create(mon_client, alarm_name, None, expr, notification_id_1, notification_id_2, notification_id_3) print('Created Alarm %s' % alarm_id) print_notification_setup(mon_client, alarm_id) print('Test initial cycle of Alarms') cycle_states(mon_client, alarm_id, states) # Ensure proper notifications got written to each if not check_notifications(alarm_id, email1, email2, email3, states[0], states[1], states[2], 0): return 1 # Disable alarm. Cycle OK, ALARM, UNDETERMINED, print('Disable Alarm') alarm.disable(mon_client, alarm_id) cycle_states(mon_client, alarm_id, states) # Ensure no new notifications if not check_notifications(alarm_id, email1, email2, email3, states[0], states[1], states[2], 0): return 1 # Enable alarm. Cycle OK, ALARM, UNDETERMINED print('Enable Alarm') alarm.enable(mon_client, alarm_id) cycle_states(mon_client, alarm_id, states) # Ensure proper notifications got written to each if not check_notifications(alarm_id, email1, email2, email3, states[0], states[1], states[2], 1): return 1 # Switch Alarm notifications around. Cycle OK, ALARM, UNDETERMINED, print("Switch around Alarm notifications") alarm.patch(mon_client, alarm_id, {'ok_actions': [notification_id_2], 'alarm_actions': [notification_id_3], 'undetermined_actions': [notification_id_1]}) print_notification_setup(mon_client, alarm_id) cycle_states(mon_client, alarm_id, states) # Ensure proper notifications got written to each if not check_notifications(alarm_id, email2, email3, email1, states[0], states[1], states[2], 2): return 1 # Switch the email addresses around. Cycle OK, ALARM, UNDETERMINED, # Ensure proper notifications got written to each return 0 except exc.HTTPException as he: print(he.code) print(he.message) return 1
def main(): if not utils.ensure_has_notification_engine(): return 1 mail_host = 'localhost' metric_host = subprocess.check_output(['hostname', '-f']).strip() utils.setup_cli() notification_name = 'Jahmon Smoke Test' notification_email_addr = 'root@' + mail_host alarm_name = 'high cpu and load' metric_name = 'load_avg_1_min' metric_dimensions = {'hostname': metric_host} cleanup(notification_name, alarm_name) # Query how many metrics there are for the Alarm initial_num_metrics = count_metrics(metric_name, metric_dimensions) if initial_num_metrics is None: return 1 start_time = time.time() # Create Notification through CLI notification_id = cli_wrapper.create_notification(notification_name, notification_email_addr) # Create Alarm through CLI expression = 'max(cpu_system_perc) > 0 and ' + \ 'max(load_avg_1_min{hostname=' + metric_host + '}) > 0' description = 'System CPU Utilization exceeds 1% and ' + \ 'Load exceeds 3 per measurement period' alarm_id = cli_wrapper.create_alarm(alarm_name, expression, description=description, ok_notif_id=notification_id, alarm_notif_id=notification_id, undetermined_notif_id=notification_id) # Ensure it is created in the right state initial_state = 'UNDETERMINED' if not utils.check_alarm_state(alarm_id, initial_state): return 1 states = [] states.append(initial_state) state = wait_for_alarm_state_change(alarm_id, initial_state) if state is None: return 1 if state != 'ALARM': print('Wrong final state, expected ALARM but was %s' % state, file=sys.stderr) return 1 states.append(state) new_state = 'OK' states.append(new_state) cli_wrapper.change_alarm_state(alarm_id, new_state) # There is a bug in the API which allows this to work. Soon that # will be fixed and this will fail if len(sys.argv) > 1: final_state = 'ALARM' states.append(final_state) state = wait_for_alarm_state_change(alarm_id, new_state) if state is None: return 1 if state != final_state: print('Wrong final state, expected %s but was %s' % (final_state, state), file=sys.stderr) return 1 # If the alarm changes state too fast, then there isn't time for the new # metric to arrive. Unlikely, but it has been seen ensure_at_least(time.time() - start_time, 35) change_time = time.time() - start_time final_num_metrics = count_metrics(metric_name, metric_dimensions) if final_num_metrics <= initial_num_metrics: print('No new metrics received in %d seconds' % change_time, file=sys.stderr) return 1 print('Received %d metrics in %d seconds' % ((final_num_metrics - initial_num_metrics), change_time)) if not utils.check_alarm_history(alarm_id, states): return 1 # Notifications are only sent out for the changes, so omit the first state if not check_notifications(alarm_id, states[1:]): return 1 return 0