-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Various fixes to the Zabbix system on esdc-mon (#119)
* Various fixes to the Zabbix system on esdc-mon related to erigones/esdc-factory#29, erigones/esdc-factory#30 and other commits in the 2.5.2 release of esdc-mon appliance * Remove old rabbitmq check after t_svc-mq upgrade related to commit erigones/esdc-factory#7d25bf38c942fecde153e9e3b6a2aa72d951442d * More monitoring fixes - commit erigones/esdc-factory#3ad5f55 * Updated Zabbix library modules (PyCharm inspection)
- Loading branch information
Showing
27 changed files
with
9,885 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# (c) 2012-2017, Erigones, s. r. o | ||
try: | ||
from zabbix_api import ZabbixAPI, ZabbixAPIException | ||
except ImportError: | ||
ZabbixAPI = ZabbixAPIException = None | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
|
||
|
||
def main(): | ||
# noinspection PyShadowingBuiltins | ||
module = AnsibleModule( | ||
argument_spec=dict( | ||
server_url=dict(required=True, default=None, aliases=['url']), | ||
login_user=dict(required=True), | ||
login_password=dict(required=True), | ||
api_method=dict(required=True), | ||
api_params_dict=dict(required=False, type='dict', default={}), | ||
api_params_list=dict(required=False, type='list', default=[]), | ||
timeout=dict(default=10, type='int'), | ||
validate_certs=dict(required=False, default=False, type='bool') | ||
), | ||
supports_check_mode=True | ||
) | ||
|
||
if not ZabbixAPI: | ||
module.fail_json(msg="Missing required zabbix-api module (check docs or install with: " | ||
"pip install zabbix-api-erigones)") | ||
raise AssertionError | ||
|
||
server_url = module.params['server_url'] | ||
login_user = module.params['login_user'] | ||
login_password = module.params['login_password'] | ||
api_method = module.params['api_method'] | ||
api_params = module.params['api_params_list'] or module.params['api_params_dict'] | ||
timeout = module.params['timeout'] | ||
ssl_verify = module.params['validate_certs'] | ||
|
||
# login to zabbix | ||
try: | ||
# noinspection PyCallingNonCallable | ||
zbx = ZabbixAPI(server=server_url, timeout=timeout, ssl_verify=ssl_verify) | ||
zbx.login(login_user, login_password) | ||
except Exception as e: | ||
module.fail_json(msg="Failed to connect to Zabbix server: %s" % e) | ||
raise AssertionError | ||
|
||
try: | ||
result = zbx.call(api_method, api_params) | ||
except ZabbixAPIException as e: | ||
module.fail_json(msg="Zabbix API error: %s" % e) | ||
raise AssertionError | ||
except Exception as e: | ||
module.fail_json(msg="Unknown failure: %s" % e) | ||
raise AssertionError | ||
else: | ||
if api_method.endswith(('.get', '.isreadable', '.iswritable')): | ||
changed = False | ||
else: | ||
changed = True | ||
|
||
module.exit_json(changed=changed, result=result) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
- name: upgrading to {{ tasklist|basename }} | ||
- name: Upgrading to {{ tasklist|basename }} | ||
set_fact: | ||
upgrading_to: "{{ tasklist|basename }}" | ||
upgrading_to: "{{ tasklist|basename }}" | ||
current_task_dir: "{{ upg_dir }}/{{ tasklist|basename }}" | ||
|
||
- include: "{{ upg_dir }}/{{ upgrading_to }}/main.yml" | ||
- include: "{{ current_task_dir }}/main.yml" | ||
|
||
- meta: flush_handlers | ||
|
||
- name: bumping appliance version | ||
- name: Bumping appliance version | ||
shell: echo "{{ upgrading_to }}" > "{{ versionfile }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# output is 3 lines: | ||
# 1: zabbix api url | ||
# 2: user | ||
# 3: pass | ||
- name: Query Zabbix credentials | ||
local_action: | ||
module: shell | ||
args: python -c 'from vms.models import DefaultDc; print(DefaultDc().settings.MON_ZABBIX_SERVER); print(DefaultDc().settings.MON_ZABBIX_USERNAME); print(DefaultDc().settings.MON_ZABBIX_PASSWORD);' | ||
environment: | ||
ERIGONES_HOME: "{{ erigones_home }}" | ||
PYTHONPATH: "{{ erigones_home }}:$PYTHONPATH" | ||
VIRTUAL_ENV: "{{ erigones_home }}/envs" | ||
PATH: "{{ erigones_home }}/bin:{{ erigones_home }}/envs/bin:$PATH" | ||
DJANGO_SETTINGS_MODULE: "core.settings" | ||
register: zabbix_credentials | ||
|
||
- name: Set Zabbix credentials | ||
set_fact: | ||
zabbix_url: "{{ zabbix_credentials.stdout_lines[0] }}" | ||
zabbix_login_user: "{{ zabbix_credentials.stdout_lines[1] }}" | ||
zabbix_login_password: "{{ zabbix_credentials.stdout_lines[2] }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,25 @@ | ||
# This task searches for directory zabbix_templates in current task dir (e.g. v2.4.0/zabbix_templates) | ||
# and imports all .json files that are present there. | ||
# Required variables: upg_dir, upgrading_to | ||
# Required variables: current_task_dir (=upg_dir/upgrading_to) | ||
# Required tasks: zabbix_credentials.yml | ||
|
||
- name: Preparing to update zabbix monitoring templates | ||
set_fact: | ||
tmpl_dir: '{{ upg_dir }}/{{ upgrading_to }}/files/zabbix_templates' | ||
tmpl_dir: '{{ current_task_dir }}/files/zabbix_templates' | ||
|
||
- name: Get list of new templates | ||
local_action: | ||
module: shell | ||
args: find "{{ tmpl_dir }}" -name \*.json -type f -exec basename {} \; | ||
register: tmpl_list | ||
|
||
# output is 3 lines: | ||
# 1: zabbix api url | ||
# 2: user | ||
# 3: pass | ||
- name: Query Zabbix credentials | ||
local_action: | ||
module: shell | ||
args: python -c 'from vms.models import DefaultDc; print(DefaultDc().settings.MON_ZABBIX_SERVER); print(DefaultDc().settings.MON_ZABBIX_USERNAME); print(DefaultDc().settings.MON_ZABBIX_PASSWORD);' | ||
environment: | ||
ERIGONES_HOME: "{{ erigones_home }}" | ||
PYTHONPATH: "{{ erigones_home }}:$PYTHONPATH" | ||
VIRTUAL_ENV: "{{ erigones_home }}/envs" | ||
PATH: "{{ erigones_home }}/bin:{{ erigones_home }}/envs/bin:$PATH" | ||
DJANGO_SETTINGS_MODULE: "core.settings" | ||
register: zabbix_credentials | ||
|
||
- name: Import monitoring templates | ||
local_action: | ||
module: zabbix_template | ||
url="{{ zabbix_credentials.stdout_lines[0] }}" | ||
login_user="{{ zabbix_credentials.stdout_lines[1] }}" | ||
login_password="{{ zabbix_credentials.stdout_lines[2] }}" | ||
url="{{ zabbix_url }}" | ||
login_user="{{ zabbix_login_user }}" | ||
login_password="{{ zabbix_login_password }}" | ||
state=import | ||
format=json | ||
template="{{ tmpl_dir }}/{{ item }}" | ||
with_items: "{{ tmpl_list.stdout.split('\n') }}" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
- name: Load Zabbix credentials | ||
include: "{{ upg_base }}/lib/zabbix_credentials.yml" | ||
|
||
- include: "{{ upg_base }}/lib/zabbix_import_templates.yml" | ||
|
||
- name: Update fixed Zabbix templates | ||
include: "{{ upg_base }}/lib/zabbix_import_templates.yml" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
|
||
- name: Delete hardcoded hostname from /etc/hosts | ||
lineinfile: dest=/etc/hosts line="127.0.0.1 mon01" state=absent | ||
|
||
- name: Update postgresql config | ||
copy: src="{{ upg_dir }}/{{ upgrading_to }}/files/pg-ansible.conf" dest=/var/lib/pgsql/9.5/data/conf.d/ansible.conf | ||
copy: src="{{ current_task_dir }}/files/pg-ansible.conf" dest=/var/lib/pgsql/9.5/data/conf.d/ansible.conf | ||
notify: restart postgresql95 | ||
|
||
- include: "{{ upg_base }}/lib/zabbix_import_templates.yml" | ||
- name: Load Zabbix credentials | ||
include: "{{ upg_base }}/lib/zabbix_credentials.yml" | ||
|
||
- name: Update fixed Zabbix templates | ||
include: "{{ upg_base }}/lib/zabbix_import_templates.yml" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env python | ||
|
||
import sys | ||
import requests | ||
|
||
__USERNAME__ = '@USERNAME@' | ||
__PASSWORD__ = '@PASSWORD@' # md5 hash | ||
__FROM__ = '@FROM@' | ||
|
||
|
||
def login_data(): | ||
""" | ||
Login credentials in HQSMS service. | ||
""" | ||
return { | ||
'username': __USERNAME__, | ||
'password': __PASSWORD__, | ||
'from': __FROM__, | ||
} | ||
|
||
def sms_send(phone, message): | ||
""" | ||
Send text message. | ||
""" | ||
data = login_data() | ||
data['to'] = phone.replace('+', '') | ||
data['message'] = message | ||
|
||
return requests.post("https://ssl.hqsms.com/sms.do", data) | ||
|
||
|
||
if __name__ == '__main__': | ||
if len(sys.argv) < 3: | ||
sys.stderr.write('Usage: %s <phone> <message>\n' % sys.argv[0]) | ||
sys.exit(1) | ||
|
||
msg = str(' '.join(sys.argv[2:])) | ||
r = sms_send(sys.argv[1], msg[:160]) | ||
|
||
print('%s (%s)' % (r.text, r.status_code)) | ||
|
||
if r.status_code == 200 and r.text.startswith('OK:'): | ||
sys.exit(0) | ||
|
||
sys.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/sh | ||
|
||
JID=${1} | ||
shift | ||
MSG=$(echo "${@}" | sed 's/|\?\*UNKNOWN\*|\?//g') | ||
|
||
curl -s -m 3 -o /dev/null -d "jid=${JID}&msg=${MSG}" http://127.0.0.1:8922/alert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/sh | ||
|
||
JID=${1} | ||
shift | ||
MSG=$(echo "${@}" | sed 's/|\?\*UNKNOWN\*|\?//g') | ||
|
||
curl -s -m 3 -o /dev/null -d "jid=${JID}&msg=${MSG}" http://127.0.0.1:8922/alert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
PHONE="${1}" # Set this in user media | ||
shift | ||
# Everything else is the message itself | ||
MSG=$(echo "${@}" | sed 's/|\?\*UNKNOWN\*|\?//g') | ||
|
||
/etc/zabbix/alertscripts/hqsms.py "${PHONE}" "${MSG}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Ludolph systemd service file | ||
# | ||
[Unit] | ||
Description=Ludolph - Monitoring Jabber Bot | ||
Documentation=https://github.com/erigones/Ludolph | ||
After=network.target zabbix-server.service | ||
|
||
[Service] | ||
Type=simple | ||
User=ludolph | ||
ExecStart=/usr/bin/ludolph | ||
Restart=on-failure | ||
RestartPreventExitStatus=2 | ||
RestartSec=30 | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
Oops, something went wrong.