diff --git a/check_ip_address.r2py b/check_ip_address.r2py new file mode 100644 index 0000000..886dec5 --- /dev/null +++ b/check_ip_address.r2py @@ -0,0 +1,64 @@ +def is_valid_ip_address(ipaddr): + """ + + Determines if ipaddr is a valid IP address. + 0.X and 224-255.X addresses are not allowed. + Additionally, 192.168.0.0 is not allowed. + + + ipaddr: String to check for validity. (It will check that this is a string). + + + True if a valid IP, False otherwise. + """ + # Argument must be of the string type + if not type(ipaddr) == str: + log("IP address is not string type") + return False + + if ipaddr == '192.168.0.0': + log("IP address 192.168.0.0 is not allowed!!") + return False + + # A valid IP should have 4 segments, explode on the period + octets = ipaddr.split(".") + + # Check that we have 4 parts + if len(octets) != 4: + return False + + # Check that each segment is a number between 0 and 255 inclusively. + for octet in octets: + # Attempt to convert to an integer + try: + ipnumber = int(octet) + except ValueError: + # There was an error converting to an integer, not an IP + log("IP address should have integer value!") + return False + + # IP addresses octets must be between 0 and 255 + if not (ipnumber >= 0 and ipnumber <= 255): + log("IP address should be in range of 0-255") + return False + + # should not have a ValueError (I already checked) + firstipnumber = int(octets[0]) + + # IP addresses with the first octet 0 refer to all local IPs. These are + # not allowed + if firstipnumber == 0: + log("First Octet of IP address cannot be zero!") + return False + + # IP addresses with the first octet >=224 are either Multicast or reserved. + # These are not allowed + if firstipnumber >= 224: + log("Multicast address are not allowed to be used!") + return False + + # At this point, assume the IP is valid + log("The IP address mentioned is valid!") + return True + + diff --git a/tests/ut_monitor_check_advertiseserver.py b/tests/ut_monitor_check_advertiseserver.py new file mode 100644 index 0000000..536d05b --- /dev/null +++ b/tests/ut_monitor_check_advertiseserver.py @@ -0,0 +1,25 @@ +import sys +import os +import subprocess +import monitor_processes + +#pragma out All critical processes on -seattle are up and running + +#Creating dummy advertiseserver process +advertiseserver_file=open("advertiseserver.py","w") +advertiseserver_file.write('raw_input("enter something")') +advertiseserver_file.close() + + +proc = subprocess.Popen([sys.executable, 'advertiseserver.py']) + + +monitor_process_list = ['python advertiseserver.py'] +command_list =["ps auwx | grep python | grep -v grep"] +machine_name ='-seattle' +monitor_output = monitor_processes.monitor_processes(monitor_process_list, command_list, machine_name) +#killing to avoid script hang +proc.kill() +expected_out = "All critical processes on seattle are up and running" + + diff --git a/tests/ut_monitor_check_backenddaemon.py b/tests/ut_monitor_check_backenddaemon.py new file mode 100644 index 0000000..02d904a --- /dev/null +++ b/tests/ut_monitor_check_backenddaemon.py @@ -0,0 +1,21 @@ +import sys +import subprocess +import monitor_processes + +#pragma out All critical processes on -seattleclearinghouse are up and running + +""" +Trying to build dummy backend_daemon.py process +in the local machine for unit test +""" +file=open("backend_daemon.py","w") +file.write('raw_input("enter something")') +file.close() +proc = subprocess.Popen([sys.executable, 'backend_daemon.py']) + +monitor_process_list=['python backend_daemon.py'] +command_list = ["ps auwx | grep python| grep -v grep"] +machine_name = "-seattleclearinghouse" +monitor_processes.monitor_processes(monitor_process_list, command_list, machine_name) +proc.kill() +expected_out = "All critical processes on seattleclearinghouse are up and running" diff --git a/tests/ut_monitor_check_checkactivedbnodes.py b/tests/ut_monitor_check_checkactivedbnodes.py new file mode 100644 index 0000000..d98e997 --- /dev/null +++ b/tests/ut_monitor_check_checkactivedbnodes.py @@ -0,0 +1,22 @@ +import sys +import subprocess +import monitor_processes + +#pragma out All critical processes on -seattleclearinghouse are up and running + +""" +Trying to build dummy check_active_db_nodes.py process +in the local machine for unit test +""" +file=open("check_active_db_nodes.py","w") +file.write('raw_input("enter something")') +file.close() +proc = subprocess.Popen([sys.executable, 'check_active_db_nodes.py']) + +monitor_process_list=['python check_active_db_nodes.py'] +command_list = ["ps auwx | grep python| grep -v grep"] +machine_name = "-seattleclearinghouse" +monitor_processes.monitor_processes(monitor_process_list, command_list, machine_name) +#killing to avoid script hang +proc.kill() +expected_out = "All critical processes on -seattleclearinghouse are up and running" diff --git a/tests/ut_monitor_check_clearinghouse_transition_onepercentmanyevents_to_canonical.py b/tests/ut_monitor_check_clearinghouse_transition_onepercentmanyevents_to_canonical.py new file mode 100644 index 0000000..358cb70 --- /dev/null +++ b/tests/ut_monitor_check_clearinghouse_transition_onepercentmanyevents_to_canonical.py @@ -0,0 +1,22 @@ +import sys +import subprocess +import monitor_processes +#pragma out All critical processes on -seattleclearinghouse are up and running + +""" +Trying to build dummy transition_onepercentmanyevents_to_canonical.py process +in the local machine for unit test +""" +file=open("transition_onepercentmanyevents_to_canonical.py","w") +file.write('raw_input("enter something")') +file.close() +proc = subprocess.Popen([sys.executable, 'transition_onepercentmanyevents_to_canonical.py']) + +monitor_process_list=['python transition_onepercentmanyevents_to_canonical.py'] +command_list = ["ps auwx | grep python| grep -v grep"] +machine_name = "-seattleclearinghouse" +monitor_processes.monitor_processes(monitor_process_list, command_list, machine_name) +#killing to avoid script hang +proc.kill() + +expected_out = "All critical processes on -seattleclearinghouse are up and running" diff --git a/tests/ut_monitor_check_lockserverdaemon.py b/tests/ut_monitor_check_lockserverdaemon.py new file mode 100644 index 0000000..42c2f90 --- /dev/null +++ b/tests/ut_monitor_check_lockserverdaemon.py @@ -0,0 +1,21 @@ +import sys +import subprocess +import monitor_processes + +#pragma out All critical processes on -seattleclearinghouse are up and running + +""" +Trying to build dummy lockserver_daemon.py process +in the local machine for unit test +""" +file=open("lockserver_daemon.py","w") +file.write('raw_input("enter something")') +file.close() +proc = subprocess.Popen([sys.executable, 'lockserver_daemon.py']) + +monitor_process_list=['python lockserver_daemon.py'] +command_list = ["ps auwx | grep python| grep -v grep"] +machine_name = "-seattleclearinghouse" +monitor_processes.monitor_processes(monitor_process_list, command_list, machine_name) +proc.kill() +expected_out = "All critical processes on seattleclearinghouse are up and running" diff --git a/tests/ut_monitor_check_transitioncanonicaltotwopercent.py b/tests/ut_monitor_check_transitioncanonicaltotwopercent.py new file mode 100644 index 0000000..e977b5c --- /dev/null +++ b/tests/ut_monitor_check_transitioncanonicaltotwopercent.py @@ -0,0 +1,23 @@ +import sys +import subprocess +import monitor_processes + +#pragma out All critical processes on -seattleclearinghouse are up and running + +""" +Trying to build dummy transition_canonical_to_twopercent.py process +in the local machine for unit test +""" +file=open("transition_canonical_to_twopercent.py","w") +file.write('raw_input("enter something")') +file.close() +proc = subprocess.Popen([sys.executable, 'transition_canonical_to_twopercent.py']) + +monitor_process_list=['python transition_canonical_to_twopercent.py'] +command_list = ["ps auwx | grep python| grep -v grep"] +machine_name = "-seattleclearinghouse" +monitor_processes.monitor_processes(monitor_process_list, command_list, machine_name) +#killing to avoid script hang +proc.kill() + +expected_out = "All critical processes on -seattleclearinghouse are up and running" diff --git a/tests/ut_monitor_check_transitiondonationtocanonical.py b/tests/ut_monitor_check_transitiondonationtocanonical.py new file mode 100644 index 0000000..31edb99 --- /dev/null +++ b/tests/ut_monitor_check_transitiondonationtocanonical.py @@ -0,0 +1,19 @@ +import sys +import subprocess +import monitor_processes + +#pragma out All critical processes on -seattleclearinghouse are up and running + +""" +Trying to build dummy transition_donation_to_canonical.py process +in the local machine for unit test +""" + +monitor_process_list=['transition_donation_to_canonical.py'] +command_list = ["ps auwx | grep python| grep -v grep"] +machine_name = "-seattleclearinghouse" +monitor_processes.monitor_processes(monitor_process_list, command_list, machine_name) +#killing to avoid script hang +proc.kill() + +expected_out = "All critical processes on -seattleclearinghouse are up and running" diff --git a/tests/ut_monitor_check_transitiontwopercenttotwopercent.py b/tests/ut_monitor_check_transitiontwopercenttotwopercent.py new file mode 100644 index 0000000..c6663e2 --- /dev/null +++ b/tests/ut_monitor_check_transitiontwopercenttotwopercent.py @@ -0,0 +1,22 @@ +import sys +import subprocess +import monitor_processes + +#pragma out All critical processes on -seattleclearinghouse are up and running + +""" +Trying to build dummy transition_twopercent_to_twopercent.py process +in the local machine for unit test +""" +file=open("transition_twopercent_to_twopercent.py","w") +file.write('raw_input("enter something")') +file.close() +proc = subprocess.Popen([sys.executable, 'transition_twopercent_to_twopercent.py']) + +monitor_process_list=['python transition_twopercent_to_twopercent.py'] +command_list = ["ps auwx | grep python| grep -v grep"] +machine_name = "-seattleclearinghouse" +monitor_processes.monitor_processes(monitor_process_list, command_list, machine_name) +#killing to avoid script hang +proc.kill() +expected_out = "All critical processes on seattleclearinghouse are up and running" diff --git a/tests/ut_monitor_sendgmail.py b/tests/ut_monitor_sendgmail.py new file mode 100644 index 0000000..f5b0831 --- /dev/null +++ b/tests/ut_monitor_sendgmail.py @@ -0,0 +1,14 @@ +import sys +import subprocess +import send_gmail + +#pragma out loaded gmail info + + +def main(): + gmail_file_name = "/home/abhishek/monitor_script/seattle_gmail_info" + result = send_gmail.init_gmail('test21119@gmail.com','testmail') + + +if __name__ == "__main__": + main() diff --git a/tests/ut_seattlelib_check_ip_address.r2py b/tests/ut_seattlelib_check_ip_address.r2py new file mode 100644 index 0000000..57d6e3f --- /dev/null +++ b/tests/ut_seattlelib_check_ip_address.r2py @@ -0,0 +1,11 @@ +#pragma out The IP address mentioned is valid! + +""" +Testing whether check_ip_address.r2py works correctly, when passed +well formatted Ip returns true with a log message +""" +from repyportability import * +add_dy_support(locals()) +checkipaddr = dy_import_module('check_ip_address.r2py') +#added dummy IP value +checkipaddr.is_valid_ip_address('192.168.1.1')