def chatclusterusage(): try: verify_slack_token('GET', ALLOWED_TOKEN_LIST) verify_slack_username('GET', inspect.stack()[0][3], METHOD_ACL_USERLIST) (server_list, role_dict) = ([], {}) # server_list = ["192.168.0.1", "192.168.0.2"] (server_list, role_dict) = mdm.get_cluster_info() # TODO: avoid the hard code username = "******" ssh_port = 2702 response_url = get_response_url('GET') arg_list = [ server_list, role_dict, username, ssh_port, SSH_KEY_FILE, KEY_PASSPHRASE ] item = [ slack_send_delay_response, [response_url, ssh_query_cluster_usage, arg_list] ] slack_task_queue.put(item) print("queue: %s, Queue size: %d" % (slack_task_queue, slack_task_queue.qsize())) summary = "OK, got it" details = "On the way" return response_content(summary, details) except Exception as e: return response_content("Error!", e)
def chatproductionalerts(): try: verify_slack_token('GET', ALLOWED_TOKEN_LIST) verify_slack_username('GET', inspect.stack()[0][3], METHOD_ACL_USERLIST) content = '''{ \"text\": \"Nagios alerts: 2 critical, 3 warning.\", \"attachments\": [ { \"text\":\"Criticals: prod-app-01 check_app_mem 30m29s prod-app-02 check_app_pid 10m29s prod-es-16 check_elasticsearch_slow_query 8h17m9s prod-es-17 check_elasticsearch_slow_query 20h17m9s prod-es-17 check_elasticsearch_slow_query 2d20h17m9s \" } ] }''' resp = make_response(content, 200) resp.headers['Content-type'] = 'application/json; charset=utf-8' return resp except Exception as e: return response_content("Error!", e)
def chatjavadebug(): try: # TODO: get service name content = "TODO to be implemented" resp = make_response(content, 200) resp.headers['Content-type'] = 'application/json; charset=utf-8' return resp except Exception as e: return response_content("Error!", e)
def help(): print("queue: %s, Queue size: %d" % (slack_task_queue, slack_task_queue.qsize())) summary = "DevOps ChatOps via Slack Commands. All commands starts with /chat*" content_text = '''- /chatclusterusage: Overall resource usage, and summary by role. - /chatcloudexpense: Show cloud bills across different cloud providers. - /chatqueryhost [substring of hostname]: Query host without manual ssh. - /chathelp: Current online help usage ''' return response_content(summary, content_text)
def chatqueryhost(): try: verify_slack_token('GET', ALLOWED_TOKEN_LIST) verify_slack_username('GET', inspect.stack()[0][3], METHOD_ACL_USERLIST) response_url = get_response_url('GET') host_query_string = request.args.get('text', '').strip() hostname_ip_dict = {} # hostname_ip_dict = {'host1': '192.168.0.1', 'host2': '192.168.0.2'} hostname_ip_dict = mdm.hostname_ip_mapping() (server, hostname, err_msg) = get_host_ip(host_query_string, hostname_ip_dict) if err_msg != '': summary = "Ops. Fail to get what you need" details = err_msg return response_content(summary, details) else: (role, check_service_command, log_file) = (None, None, None) (role, check_service_command, log_file) = mdm.get_node_role_info(server) # TODO: avoid the hard code username = "******" ssh_port = 2702 arg_list = [ server, username, ssh_port, SSH_KEY_FILE, KEY_PASSPHRASE, role, check_service_command, log_file ] item = [ slack_send_delay_response, [response_url, ssh_queryhost, arg_list] ] slack_task_queue.put(item) print("queue: %s, Queue size: %d" % (slack_task_queue, slack_task_queue.qsize())) summary = "OK, got it" details = "On the way" return response_content(summary, details) except Exception as e: return response_content("Error!", e)
def chatcloudexpense(): try: verify_slack_token('GET', ALLOWED_TOKEN_LIST) verify_slack_username('GET', inspect.stack()[0][3], METHOD_ACL_USERLIST) response_url = get_response_url('GET') arg_list = [ DIGITALOCEAN_TOKEN, LINODE_TOKEN, SKIP_VM_PATTERNS, SKIP_VOLUMES_PATTERNS ] item = [ slack_send_delay_response, [response_url, cloudexpense, arg_list] ] slack_task_queue.put(item) print("queue: %s, Queue size: %d" % (slack_task_queue, slack_task_queue.qsize())) summary = "OK, got it" details = "On the way" return response_content(summary, details) except Exception as e: return response_content("Error!", e)