diff --git a/app/modules/db/smon.py b/app/modules/db/smon.py index ba2d9cd9..1282695d 100644 --- a/app/modules/db/smon.py +++ b/app/modules/db/smon.py @@ -1,4 +1,3 @@ -import logging import uuid from peewee import fn diff --git a/app/modules/server/server.py b/app/modules/server/server.py index 646970b5..dfb3dbf7 100644 --- a/app/modules/server/server.py +++ b/app/modules/server/server.py @@ -23,12 +23,12 @@ def ssh_command(server_ip: str, commands: list, **kwargs): stdin, stdout, stderr = ssh.run_command(command, timeout=timeout) stdin.close() except Exception as e: - roxywi_common.handle_exceptions(e, server_ip, f'Something wrong with SSH connection. Probably sudo with password', roxywi=1) + roxywi_common.handle_exceptions(e, server_ip, 'Something wrong with SSH connection. Probably sudo with password', roxywi=1) if stderr: for line in stderr.readlines(): if line: - roxywi_common.handle_exceptions(e, server_ip, line, roxywi=1) + roxywi_common.handle_exceptions(line, server_ip, line, roxywi=1) if kwargs.get('raw'): return stdout.readlines() @@ -40,7 +40,7 @@ def ssh_command(server_ip: str, commands: list, **kwargs): else: return stdout.read().decode(encoding='UTF-8') except Exception as e: - roxywi_common.handle_exceptions(e, server_ip, f'Something wrong with SSH connection. Probably sudo with password', roxywi=1) + roxywi_common.handle_exceptions(e, server_ip, 'Something wrong with SSH connection. Probably sudo with password', roxywi=1) def subprocess_execute(cmd): diff --git a/app/modules/tools/smon_agent.py b/app/modules/tools/smon_agent.py index 59fc7de2..b8591a86 100644 --- a/app/modules/tools/smon_agent.py +++ b/app/modules/tools/smon_agent.py @@ -38,7 +38,7 @@ def add_agent(data) -> int: try: inv, server_ips = generate_agent_inc(server_ip, 'install', agent_uuid) - run_ansible(inv, server_ips, f'smon_agent') + run_ansible(inv, server_ips, 'smon_agent') except Exception as e: common_roxywi.handle_exceptions(e, server_ip, 'Cannot install SMON agent', roxywi=1, login=1) @@ -55,7 +55,7 @@ def delete_agent(agent_id: int): agent_uuid = '' try: inv, server_ips = generate_agent_inc(server_ip, 'uninstall', agent_uuid) - run_ansible(inv, server_ips, f'smon_agent') + run_ansible(inv, server_ips, 'smon_agent') except Exception as e: common_roxywi.handle_exceptions(e, server_ip, 'error: Cannot uninstall SMON agent', roxywi=1, login=1) @@ -87,7 +87,7 @@ def send_get_request_to_agent(agent_id: int, server_ip: str, api_path: str) -> b headers = get_agent_headers(agent_id) agent_port = sql.get_setting('agent_port') try: - req = requests.get(f'http://{server_ip}:{agent_port}/{api_path}', headers=headers) + req = requests.get(f'http://{server_ip}:{agent_port}/{api_path}', headers=headers, timeout=5) return req.content except Exception as e: raise Exception(f'error: Cannot get agent status: {e}') @@ -97,7 +97,7 @@ def send_post_request_to_agent(agent_id: int, server_ip: str, api_path: str, jso headers = get_agent_headers(agent_id) agent_port = sql.get_setting('agent_port') try: - req = requests.post(f'http://{server_ip}:{agent_port}/{api_path}', headers=headers, json=json_data) + req = requests.post(f'http://{server_ip}:{agent_port}/{api_path}', headers=headers, json=json_data, timeout=5) return req.content except Exception as e: raise Exception(f'error: Cannot get agent status: {e}') @@ -107,7 +107,7 @@ def delete_check(agent_id: int, server_ip: str, check_id: int) -> bytes: headers = get_agent_headers(agent_id) agent_port = sql.get_setting('agent_port') try: - req = requests.delete(f'http://{server_ip}:{agent_port}/check/{check_id}', headers=headers) + req = requests.delete(f'http://{server_ip}:{agent_port}/check/{check_id}', headers=headers, timeout=5) return req.content except requests.exceptions.HTTPError as e: common_roxywi.logging(server_ip, f'error: Cannot delete check from agent: http error {e}', roxywi=1, login=1) diff --git a/app/scripts/ansible/roles/haproxy/tasks/configure.yml b/app/scripts/ansible/roles/haproxy/tasks/configure.yml index 765a458b..7cfeb6c3 100644 --- a/app/scripts/ansible/roles/haproxy/tasks/configure.yml +++ b/app/scripts/ansible/roles/haproxy/tasks/configure.yml @@ -3,19 +3,17 @@ src: haproxy.service.j2 dest: /usr/lib/systemd/system/haproxy.service mode: 0644 - when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS') and haproxy_from_wi is defined - + when: ansible_os_family == "RedHat" and haproxy_from_wi is defined - name: test to see if selinux is running command: getenforce register: sestatus - when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS') + when: ansible_os_family == "RedHat" changed_when: false ignore_errors: yes debugger: never - -- name: Disble SELINUX in config +- name: Disable SELINUX in config template: src: selinux.j2 dest: /etc/selinux/config @@ -24,8 +22,7 @@ - sestatus.stdout is defined - '"Enforcing" in sestatus.stdout' - -- name: Disble SELINUX in env +- name: Disable SELINUX in env shell: setenforce 0 &> /dev/null ignore_errors: yes debugger: never @@ -44,7 +41,7 @@ debugger: never when: - '"firewalld" in ansible_facts.packages' - - ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS' + - ansible_os_family == "RedHat" - ansible_facts.services["firewalld.service"]['state'] == "running" with_items: [ "{{ STAT_PORT }}", "{{ SOCK_PORT }}", "10000" ] @@ -72,6 +69,13 @@ mode: 0644 force: no +- name: Copy HAProxy state file in place. + template: + src: haproxy.state.j2 + dest: /etc/haproxy/haproxy.state + mode: 0644 + force: no + - name: Creates HAProxy stats directory file: path: /var/lib/haproxy diff --git a/app/scripts/ansible/roles/haproxy/tasks/installation.yml b/app/scripts/ansible/roles/haproxy/tasks/installation.yml index 8dd25046..e7356fcd 100644 --- a/app/scripts/ansible/roles/haproxy/tasks/installation.yml +++ b/app/scripts/ansible/roles/haproxy/tasks/installation.yml @@ -3,7 +3,7 @@ name: epel-release state: latest disable_gpg_check: yes - when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS') and HAPVER|length > 0 + when: ansible_os_family == "RedHat" and HAPVER|length > 0 ignore_errors: yes environment: http_proxy: "{{PROXY}}" @@ -12,7 +12,7 @@ - name: Set dist short name if EL set_fact: distr_short_name: "el" - when: ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS' + when: ansible_os_family == "RedHat" - name: Set dist short name if Amazon Linux set_fact: @@ -27,7 +27,7 @@ - rsyslog state: present disable_gpg_check: yes - when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS') and HAPVER|length > 0 + when: ansible_os_family == "RedHat" and HAPVER|length > 0 ignore_errors: yes register: install_result retries: 5 @@ -45,7 +45,7 @@ - rsyslog - bind-utils state: present - when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS') and ("'timed out' in install_result.stderr") + when: (ansible_os_family == "RedHat") and ("'timed out' in install_result.stderr") ignore_errors: yes register: install_result1 retries: 5 @@ -59,7 +59,7 @@ - name: set_fact from wi set_fact: haproxy_from_wi: "yes" - when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS' or ansible_distribution == 'Amazon') and HAPVER|length > 0 + when: (ansible_os_family == "RedHat"' or ansible_distribution == 'Amazon') and HAPVER|length > 0 - name: install the latest version of HAProxy @@ -69,7 +69,7 @@ - socat - rsyslog state: latest - when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS') and (install_result.rc != 0 and install_result1.rc != 0) + when: (ansible_os_family == "RedHat") and (install_result.rc != 0 and install_result1.rc != 0) register: install_result retries: 5 until: install_result.rc == 0 @@ -86,7 +86,7 @@ - socat - rsyslog state: present - when: ansible_facts['os_family'] == 'Debian' or ansible_facts['os_family'] == 'Ubuntu' + when: ansible_os_family == "Debian" environment: http_proxy: "{{PROXY}}" https_proxy: "{{PROXY}}" diff --git a/app/scripts/ansible/roles/haproxy/tasks/logs.yml b/app/scripts/ansible/roles/haproxy/tasks/logs.yml index e7baf3c9..a8388698 100644 --- a/app/scripts/ansible/roles/haproxy/tasks/logs.yml +++ b/app/scripts/ansible/roles/haproxy/tasks/logs.yml @@ -11,7 +11,7 @@ src: /var/www/haproxy-wi/app/scripts/ansible/roles/haproxy/templates/logrotate.conf.j2 dest: /etc/logrotate.d/haproxy.conf force: no - when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS') + when: ansible_os_family == "RedHat" ignore_errors: yes - name: Installing HAProxy conf for logrotate on Debian @@ -19,5 +19,5 @@ src: /var/www/haproxy-wi/app/scripts/ansible/roles/haproxy/templates/logrotate-debian.conf.j2 dest: /etc/logrotate.d/haproxy-roxy-wi force: no - when: (ansible_facts['os_family'] == "Debian" or ansible_facts['os_family'] == 'Ubuntu') + when: ansible_os_family == "Debian" ignore_errors: yes diff --git a/app/scripts/ansible/roles/haproxy/templates/haproxy.state.j2 b/app/scripts/ansible/roles/haproxy/templates/haproxy.state.j2 new file mode 100644 index 00000000..56a6051c --- /dev/null +++ b/app/scripts/ansible/roles/haproxy/templates/haproxy.state.j2 @@ -0,0 +1 @@ +1 \ No newline at end of file