Browse Source

add ansible infrastructure to manage proxmox cluster

pull/1/head
Daniel Poelzleithner 2 years ago
parent
commit
db4fd9f0cb
90 changed files with 10940 additions and 1 deletions
  1. 1
    0
      .gitignore
  2. 10
    0
      ansible/hosts
  3. 19
    0
      ansible/kubernetes.yml
  4. 173
    0
      ansible/roles/elnappo.check_mk_agent/.gitignore
  5. 20
    0
      ansible/roles/elnappo.check_mk_agent/.travis.yml
  6. 13
    0
      ansible/roles/elnappo.check_mk_agent/.yamllint
  7. 22
    0
      ansible/roles/elnappo.check_mk_agent/LICENSE
  8. 79
    0
      ansible/roles/elnappo.check_mk_agent/README.md
  9. 14
    0
      ansible/roles/elnappo.check_mk_agent/defaults/main.yml
  10. 17
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/README
  11. 170
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/apache_status
  12. 26
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/asmcmd.sh
  13. 34
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/db2_mem
  14. 48
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/dnsclient
  15. 92
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/hpux_lunstats
  16. 49
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/hpux_statgrab
  17. 85
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/isc_dhcpd
  18. 52
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/jar_signature
  19. 38
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/kaspersky_av
  20. 40
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/lnx_quota
  21. 9
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/lvm
  22. 55
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mailman_lists
  23. 65
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_apt
  24. 44
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_ceph
  25. 54
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_cups_queues
  26. 231
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_db2.aix
  27. 147
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_db2.linux
  28. 55
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_docker_container_piggybacked
  29. 33
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_filehandler
  30. 5
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_haproxy.freebsd
  31. 296
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_informix
  32. 357
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_inotify
  33. 69
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_inventory.aix
  34. 100
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_inventory.linux
  35. 91
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_inventory.solaris
  36. 34
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_iptables
  37. 523
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_jolokia
  38. 29
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_logins
  39. 564
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_logwatch
  40. 13
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_logwatch.aix
  41. 205
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_mongodb
  42. 92
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_mysql
  43. 30
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_omreport
  44. 1378
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_oracle
  45. 1152
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_oracle.aix
  46. 38
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_oracle_asm
  47. 127
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_oracle_crs
  48. 485
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_postgres
  49. 504
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_sap
  50. 78
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_sap.aix
  51. 143
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_sap_hana
  52. 41
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_saprouter
  53. 88
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_scaleio
  54. 140
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_site_object_counts
  55. 31
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_sshd_config
  56. 30
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_suseconnect
  57. 332
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_tinkerforge
  58. 82
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_tsm
  59. 50
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mk_zypper
  60. 384
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/mtr
  61. 31
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/netstat.aix
  62. 31
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/netstat.linux
  63. 38
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/nfsexports
  64. 57
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/nfsexports.solaris
  65. 146
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/nginx_status
  66. 149
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/plesk_backups
  67. 51
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/plesk_domains
  68. 84
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/runas
  69. 179
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/smart
  70. 38
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/symantec_av
  71. 89
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/unitrends_backup
  72. 50
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/unitrends_replication
  73. 50
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/vxvm
  74. 121
    0
      ansible/roles/elnappo.check_mk_agent/files/plugins/websphere_mq
  75. 1
    0
      ansible/roles/elnappo.check_mk_agent/files/sudoers_check_mk_agent
  76. 14
    0
      ansible/roles/elnappo.check_mk_agent/handlers/main.yml
  77. 249
    0
      ansible/roles/elnappo.check_mk_agent/library/check_mk.py
  78. 1
    0
      ansible/roles/elnappo.check_mk_agent/meta/.galaxy_install_info
  79. 24
    0
      ansible/roles/elnappo.check_mk_agent/meta/main.yml
  80. 16
    0
      ansible/roles/elnappo.check_mk_agent/molecule/default/INSTALL.rst
  81. 27
    0
      ansible/roles/elnappo.check_mk_agent/molecule/default/molecule.yml
  82. 19
    0
      ansible/roles/elnappo.check_mk_agent/molecule/default/playbook.yml
  83. 43
    0
      ansible/roles/elnappo.check_mk_agent/molecule/default/prepare.yml
  84. 16
    0
      ansible/roles/elnappo.check_mk_agent/molecule/default/tests/test_default.py
  85. 152
    0
      ansible/roles/elnappo.check_mk_agent/tasks/main.yml
  86. 5
    0
      ansible/roles/elnappo.check_mk_agent/test.yml
  87. 10
    0
      ansible/roles/k8s/files/check-mk-agent-socket.unit
  88. 12
    0
      ansible/roles/k8s/files/check-mk-service.unit
  89. 51
    0
      ansible/roles/k8s/tasks/main.yml
  90. 0
    1
      ansible/roles/proxmox/tasks/main.yml

+ 1
- 0
.gitignore View File

@@ -0,0 +1 @@
1
+*.retry

+ 10
- 0
ansible/hosts View File

@@ -3,3 +3,13 @@ server3.hq.c3d2.de
3 3
 server4.hq.c3d2.de 
4 4
 server5.hq.c3d2.de
5 5
 server6.hq.c3d2.de   
6
+
7
+[kubernetes]
8
+k8s-1.hq.c3d2.de        
9
+k8s-2.hq.c3d2.de        
10
+k8s-3.hq.c3d2.de        
11
+k8s-4.hq.c3d2.de        
12
+
13
+[kubernetes:vars]
14
+ansible_python_interpreter=/usr/bin/python3
15
+ansible_user=ubuntu

+ 19
- 0
ansible/kubernetes.yml View File

@@ -0,0 +1,19 @@
1
+---
2
+# file: hypervisor.yml
3
+- hosts: kubernetes
4
+  become: yes
5
+  become_user: root
6
+  become_method: sudo
7
+  vars:
8
+    check_mk_agent_over_ssh: False
9
+    check_mk_agent_monitoring_host: monit.hq.c3d2.de
10
+    check_mk_agent_monitoring_user: monitoring
11
+    check_mk_agent_add_to_wato: False
12
+    check_mk_agent_monitoring_host_wato_username: monitoring
13
+    check_mk_agent_monitoring_host_url: https://monit.hq.c3d2.de/c3d2/
14
+    # check_mk_agent_local_checks:
15
+    #   filecount:
16
+    #     src: files/check_mk_local_checks/filecount
17
+  roles:
18
+    - k8s
19
+    - elnappo.check_mk_agent

+ 173
- 0
ansible/roles/elnappo.check_mk_agent/.gitignore View File

@@ -0,0 +1,173 @@
1
+# Created by https://www.gitignore.io
2
+
3
+### OSX ###
4
+.DS_Store
5
+.AppleDouble
6
+.LSOverride
7
+
8
+# Icon must end with two \r
9
+Icon
10
+
11
+
12
+# Thumbnails
13
+._*
14
+
15
+# Files that might appear on external disk
16
+.Spotlight-V100
17
+.Trashes
18
+
19
+# Directories potentially created on remote AFP share
20
+.AppleDB
21
+.AppleDesktop
22
+Network Trash Folder
23
+Temporary Items
24
+.apdisk
25
+
26
+
27
+### Windows ###
28
+# Windows image file caches
29
+Thumbs.db
30
+ehthumbs.db
31
+
32
+# Folder config file
33
+Desktop.ini
34
+
35
+# Recycle Bin used on file shares
36
+$RECYCLE.BIN/
37
+
38
+# Windows Installer files
39
+*.cab
40
+*.msi
41
+*.msm
42
+*.msp
43
+
44
+# Windows shortcuts
45
+*.lnk
46
+
47
+
48
+### Linux ###
49
+*~
50
+
51
+# KDE directory preferences
52
+.directory
53
+
54
+### Python ###
55
+# Byte-compiled / optimized / DLL files
56
+__pycache__/
57
+*.py[cod]
58
+*$py.class
59
+
60
+# C extensions
61
+*.so
62
+
63
+# Distribution / packaging
64
+.Python
65
+build/
66
+develop-eggs/
67
+dist/
68
+downloads/
69
+eggs/
70
+.eggs/
71
+lib/
72
+lib64/
73
+parts/
74
+sdist/
75
+var/
76
+wheels/
77
+pip-wheel-metadata/
78
+share/python-wheels/
79
+*.egg-info/
80
+.installed.cfg
81
+*.egg
82
+MANIFEST
83
+
84
+# PyInstaller
85
+#  Usually these files are written by a python script from a template
86
+#  before PyInstaller builds the exe, so as to inject date/other infos into it.
87
+*.manifest
88
+*.spec
89
+
90
+# Installer logs
91
+pip-log.txt
92
+pip-delete-this-directory.txt
93
+
94
+# Unit test / coverage reports
95
+htmlcov/
96
+.tox/
97
+.nox/
98
+.coverage
99
+.coverage.*
100
+.cache
101
+nosetests.xml
102
+coverage.xml
103
+*.cover
104
+.hypothesis/
105
+.pytest_cache/
106
+
107
+# Translations
108
+*.mo
109
+*.pot
110
+
111
+# Django stuff:
112
+*.log
113
+local_settings.py
114
+db.sqlite3
115
+
116
+# Flask stuff:
117
+instance/
118
+.webassets-cache
119
+
120
+# Scrapy stuff:
121
+.scrapy
122
+
123
+# Sphinx documentation
124
+docs/_build/
125
+
126
+# PyBuilder
127
+target/
128
+
129
+# Jupyter Notebook
130
+.ipynb_checkpoints
131
+
132
+# IPython
133
+profile_default/
134
+ipython_config.py
135
+
136
+# pyenv
137
+.python-version
138
+
139
+# celery beat schedule file
140
+celerybeat-schedule
141
+
142
+# SageMath parsed files
143
+*.sage.py
144
+
145
+# Environments
146
+.env
147
+.venv
148
+env/
149
+venv/
150
+ENV/
151
+env.bak/
152
+venv.bak/
153
+
154
+# Spyder project settings
155
+.spyderproject
156
+.spyproject
157
+
158
+# Rope project settings
159
+.ropeproject
160
+
161
+# mkdocs documentation
162
+/site
163
+
164
+# mypy
165
+.mypy_cache/
166
+.dmypy.json
167
+dmypy.json
168
+
169
+# Pyre type checker
170
+.pyre/
171
+
172
+### Python Patch ###
173
+.venv/

+ 20
- 0
ansible/roles/elnappo.check_mk_agent/.travis.yml View File

@@ -0,0 +1,20 @@
1
+---
2
+language: python
3
+services: docker
4
+
5
+env:
6
+  matrix:
7
+    - MOLECULE_DISTRO: ubuntu1604
8
+    - MOLECULE_DISTRO: ubuntu1804
9
+    - MOLECULE_DISTRO: debian8
10
+    - MOLECULE_DISTRO: debian9
11
+    - MOLECULE_DISTRO: centos7
12
+
13
+install:
14
+  - pip install molecule docker
15
+
16
+script:
17
+  - molecule test
18
+
19
+notifications:
20
+  webhooks: https://galaxy.ansible.com/api/v1/notifications/

+ 13
- 0
ansible/roles/elnappo.check_mk_agent/.yamllint View File

@@ -0,0 +1,13 @@
1
+extends: default
2
+
3
+rules:
4
+  braces:
5
+    max-spaces-inside: 1
6
+    level: error
7
+  brackets:
8
+    max-spaces-inside: 1
9
+    level: error
10
+  line-length: disable
11
+  # NOTE(retr0h): Templates no longer fail this lint rule.
12
+  #               Uncomment if running old Molecule templates.
13
+  # truthy: disable

+ 22
- 0
ansible/roles/elnappo.check_mk_agent/LICENSE View File

@@ -0,0 +1,22 @@
1
+The MIT License (MIT)
2
+
3
+Copyright (c) 2015 elnappo
4
+
5
+Permission is hereby granted, free of charge, to any person obtaining a copy
6
+of this software and associated documentation files (the "Software"), to deal
7
+in the Software without restriction, including without limitation the rights
8
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+copies of the Software, and to permit persons to whom the Software is
10
+furnished to do so, subject to the following conditions:
11
+
12
+The above copyright notice and this permission notice shall be included in all
13
+copies or substantial portions of the Software.
14
+
15
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+SOFTWARE.
22
+

+ 79
- 0
ansible/roles/elnappo.check_mk_agent/README.md View File

@@ -0,0 +1,79 @@
1
+# ansible-role-check-mk-agent
2
+[![Build Status](https://travis-ci.org/elnappo/ansible-role-check-mk-agent.svg?branch=master)](https://travis-ci.org/elnappo/ansible-role-check-mk-agent) [![Ansible Galaxy](https://img.shields.io/badge/galaxy-elnappo.check--mk--agent-blue.svg?style=flat)](https://galaxy.ansible.com/elnappo/check-mk-agent/)
3
+
4
+Installs check mk\_agent. Run it with systemd-socket, SSH with sudo or SSH as root (default). Get more information about check\_mk at [https://mathias-kettner.de/check_mk.html]()
5
+
6
+## Features
7
+* Install check_mk agent
8
+* Query check_mk agent over systemd-socket (only with check_mk_agent >= v1.4), SSH as root or SSH with sudo
9
+* Setup firewall if systemd-socket ist used (ufw or firewalld)
10
+* Add SSH host key to check_mk server
11
+* Install check_mk agent plugins/local checks and their dependencies
12
+* **Add hosts to check_mk server via WATO API**
13
+
14
+## Requirements
15
+* Python requests >= v2.5.0
16
+
17
+Tested on Ubuntu 16.04, 18.04 and CentOS 7, should also run under Debian and RedHat.
18
+
19
+## Install
20
+    $ ansible-galaxy install elnappo.check_mk_agent
21
+
22
+## Role Variables
23
+* `check_mk_agent_over_ssh: True`
24
+* `check_mk_agent_with_sudo: False` Adds a user which is allowed to run check_mk_agent with sudo
25
+* `check_mk_agent_add_host_pubkey: False` Import SSH host keys into your check_mk servers known_hosts file
26
+* `check_mk_agent_monitoring_host:` Hostname of your check_mk server
27
+* `check_mk_agent_monitoring_user:` Username under which your check_mk instance runs
28
+* `check_mk_agent_plugins_requirements: []` Requirements for extra plugins
29
+* `check_mk_agent_plugins: []` List of extra plugins to install
30
+* `check_mk_agent_local_checks: {}`
31
+* `check_mk_agent_pubkey_file:` Path to SSH pubkey file
32
+* `check_mk_agent_add_to_wato: False`
33
+* `check_mk_agent_monitoring_host_folder: ""`
34
+* `check_mk_agent_monitoring_host_discovery_mode: new`
35
+* `check_mk_agent_monitoring_host_url:`
36
+* `check_mk_agent_monitoring_host_wato_username:`
37
+* `check_mk_agent_monitoring_host_wato_secret:`
38
+* `check_mk_agent_setup_firewall: True` Add firewall rule (ufw/firewalld) when using systemd-socket
39
+* `check_mk_agent_manual_install: False` Leave agent package installation to the user
40
+
41
+## Included check_mk extra plugins
42
+Could be found under `files/plugins/`. As it is hard to keep these plugins
43
+up-to-date, these will be removed in a future version from the repository.
44
+
45
+
46
+## Dependencies
47
+None.
48
+
49
+## Example Playbook
50
+
51
+```yaml
52
+- hosts: servers
53
+  vars:
54
+    check_mk_agent_pubkey_file: omd_rsa.pub
55
+    check_mk_agent_add_host_pubkey: True
56
+    check_mk_agent_monitoring_host: checkmk.example.com
57
+    check_mk_agent_monitoring_user: monitoring
58
+    check_mk_agent_add_to_wato: True
59
+    check_mk_agent_monitoring_host_url: http://cmk.example.com/monitoring/
60
+    check_mk_agent_monitoring_host_wato_username: ansible
61
+    check_mk_agent_monitoring_host_wato_secret: 7JTuBt6nETYHG1GS
62
+    check_mk_agent_local_checks:
63
+      filecount:
64
+        src: files/check_mk_local_checks/filecount
65
+        cache_time: 600
66
+      filestat:
67
+        src: files/check_mk_local_checks/filestat
68
+
69
+  roles:
70
+     - elnappo.check_mk_agent
71
+```
72
+
73
+## License
74
+
75
+MIT
76
+
77
+## Author Information
78
+
79
+elnappo <elnappo@nerdpol.io>

+ 14
- 0
ansible/roles/elnappo.check_mk_agent/defaults/main.yml View File

@@ -0,0 +1,14 @@
1
+---
2
+# defaults file for check_mk agent
3
+check_mk_agent_over_ssh: true
4
+check_mk_agent_with_sudo: false
5
+check_mk_agent_add_host_pubkey: false
6
+check_mk_agent_plugins_requirements: []
7
+check_mk_agent_plugins: []
8
+check_mk_agent_local_checks: {}
9
+check_mk_agent_pubkey_file:
10
+check_mk_agent_add_to_wato: false
11
+check_mk_agent_monitoring_host_folder: ""
12
+check_mk_agent_monitoring_host_discovery_mode: "new"
13
+check_mk_agent_setup_firewall: true
14
+check_mk_agent_manual_install: false

+ 17
- 0
ansible/roles/elnappo.check_mk_agent/files/plugins/README View File

@@ -0,0 +1,17 @@
1
+These plugins can be installed in the plugins directory of the Linux agent
2
+in /usr/lib/check_mk_agent/plugins/. Please only install the plugins that
3
+you really need.
4
+
5
+If you want a plugin to be run asynchronously and also in
6
+a larger interval then the normal check interval, then you can
7
+copy it to a subdirectory named after a number of *minutes*,
8
+e.g.:
9
+
10
+/usr/lib/check_mk_agent/plugins/60/mk_zypper
11
+
12
+In that case the agent will:
13
+
14
+ - Run this plugin in the background and wait not for it to finish.
15
+ - Store the result of the plugin in a cache file below /etc/check_mk/cache.
16
+ - Use that file for one hour before running the script again.
17
+

+ 170
- 0
ansible/roles/elnappo.check_mk_agent/files/plugins/apache_status View File

@@ -0,0 +1,170 @@
1
+#!/usr/bin/python
2
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
3
+# +------------------------------------------------------------------+
4
+# |             ____ _               _        __  __ _  __           |
5
+# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
6
+# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
7
+# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
8
+# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
9
+# |                                                                  |
10
+# | Copyright Mathias Kettner 2014             mk@mathias-kettner.de |
11
+# +------------------------------------------------------------------+
12
+#
13
+# This file is part of Check_MK.
14
+# The official homepage is at http://mathias-kettner.de/check_mk.
15
+#
16
+# check_mk is free software;  you can redistribute it and/or modify it
17
+# under the  terms of the  GNU General Public License  as published by
18
+# the Free Software Foundation in version 2.  check_mk is  distributed
19
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
20
+# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
21
+# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
22
+# tails. You should have  received  a copy of the  GNU  General Public
23
+# License along with GNU Make; see the file  COPYING.  If  not,  write
24
+# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
25
+# Boston, MA 02110-1301 USA.
26
+
27
+# Check_MK-Agent-Plugin - Apache Server Status
28
+#
29
+# Fetches the server-status page from detected or configured apache
30
+# processes to gather status information about this apache process.
31
+#
32
+# To make this agent plugin work you have to load the status_module
33
+# into your apache process. It is also needed to enable the "server-status"
34
+# handler below the URL "/server-status".
35
+#
36
+# By default this plugin tries to detect all locally running apache processes
37
+# and to monitor them. If this is not good for your environment you might
38
+# create an apache_status.cfg file in MK_CONFDIR and populate the servers
39
+# list to prevent executing the detection mechanism.
40
+#
41
+# It is also possible to override or extend the ssl_ports variable to make the
42
+# check contact other ports than 443 with HTTPS requests.
43
+
44
+import os, sys, urllib2, re, socket
45
+
46
+config_dir = os.getenv("MK_CONFDIR", "/etc/check_mk")
47
+config_file = config_dir + "/apache_status.conf"
48
+
49
+if not os.path.exists(config_file):
50
+    config_file = config_dir + "/apache_status.cfg"
51
+
52
+# We have to deal with socket timeouts. Python > 2.6
53
+# supports timeout parameter for the urllib2.urlopen method
54
+# but we are on a python 2.5 system here which seem to use the
55
+# default socket timeout. We are local here so  set it to 1 second.
56
+socket.setdefaulttimeout(5.0)
57
+
58
+# None or list of (proto, ipaddress, port) tuples.
59
+# proto is 'http' or 'https'
60
+servers = None
61
+ssl_ports = [ 443, ]
62
+
63
+if os.path.exists(config_file):
64
+    execfile(config_file)
65
+
66
+
67
+def try_detect_servers():
68
+    results = []
69
+
70
+    for line in os.popen('netstat -tlnp 2>/dev/null').readlines():
71
+        parts = line.split()
72
+        # Skip lines with wrong format
73
+        if len(parts) < 7 or '/' not in parts[6]:
74
+            continue
75
+
76
+        pid, proc = parts[6].split('/', 1)
77
+        to_replace = re.compile('^.*/')
78
+        proc = to_replace.sub('', proc)
79
+
80
+        procs = [ 'apache2', 'httpd', 'httpd2-prefork', 'httpd2-worker', 'httpd.worker', 'fcgi-pm' ]
81
+        # the pid/proc field length is limited to 19 chars. Thus in case of
82
+        # long PIDs, the process names are stripped of by that length.
83
+        # Workaround this problem here
84
+        procs = [ p[:19 - len(pid) - 1] for p in procs ]
85
+
86
+        # Skip unwanted processes
87
+        if proc not in procs:
88
+            continue
89
+
90
+        address, port = parts[3].rsplit(':', 1)
91
+        port = int(port)
92
+
93
+        # Use localhost when listening globally
94
+        if address == '0.0.0.0':
95
+            address = '127.0.0.1'
96
+        elif address == '::':
97
+            address = '[::1]'
98
+        elif ':' in address:
99
+            address = '[%s]' % address
100
+
101
+        # Switch protocol if port is SSL port. In case you use SSL on another
102
+        # port you would have to change/extend the ssl_port list
103
+        if port in ssl_ports:
104
+            proto = 'https'
105
+        else:
106
+            proto = 'http'
107
+
108
+        results.append((proto, address, port))
109
+
110
+    return results
111
+
112
+
113
+if servers is None:
114
+    servers = try_detect_servers()
115
+
116
+
117
+if not servers:
118
+    sys.exit(0)
119
+
120
+
121
+sys.stdout.write('<<<apache_status>>>\n')
122
+for server in servers:
123
+    if isinstance(server, tuple):
124
+        proto, address, port = server
125
+        page = 'server-status'
126
+    else:
127
+        proto = server['protocol']
128
+        address = server['address']
129
+        port = server['port']
130
+        page = server.get('page', 'server-status')
131
+
132
+    portspec = port and ":%d" % port or ""
133
+
134
+    try:
135
+        url = '%s://%s%s/%s?auto' % (proto, address, portspec, page)
136
+        # Try to fetch the status page for each server
137
+        try:
138
+            request = urllib2.Request(url, headers={"Accept" : "text/plain"})
139
+            fd = urllib2.urlopen(request)
140
+        except urllib2.URLError, e:
141
+            if 'unknown protocol' in str(e):
142
+                # HACK: workaround misconfigurations where port 443 is used for
143
+                # serving non ssl secured http
144
+                url = 'http://%s%s/server-status?auto' % (address, portspec)
145
+                fd = urllib2.urlopen(url)
146
+            else:
147
+                raise
148
+        except Exception, e:
149
+            if 'doesn\'t match' in str(e):
150
+                # HACK: workaround if SSL port is found and localhost is using
151
+                # SSL connections but certificate does not match
152
+                portspec = ':80'
153
+                url = 'http://%s%s/server-status?auto' % (address, portspec)
154
+                fd = urllib2.urlopen(url)
155
+            else:
156
+                raise
157
+
158
+        for line in fd.read().split('\n'):
159
+            if not line.strip():
160
+                continue
161
+            if line.lstrip()[0] == '<':
162
+                # Seems to be html output. Skip this server.
163
+                break
164
+
165
+            sys.stdout.write("%s %s %s\n" % (address, port, line))
166
+    except urllib2.HTTPError, e:
167
+        sys.stderr.write('HTTP-Error (%s%s): %s %s\n' % (address, portspec, e.code, e))
168
+
169
+    except Exception, e:
170
+        sys.stderr.write('Exception (%s%s): %s\n' % (address, portspec, e))

+ 26
- 0
ansible/roles/elnappo.check_mk_agent/files/plugins/asmcmd.sh View File

@@ -0,0 +1,26 @@
1
+#!/bin/sh
2
+# +------------------------------------------------------------------+
3
+# |             ____ _               _        __  __ _  __           |
4
+# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
5
+# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
6
+# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
7
+# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
8
+# |                                                                  |
9
+# | Copyright Mathias Kettner 2014             mk@mathias-kettner.de |
10
+# +------------------------------------------------------------------+
11
+#
12
+# This file is part of Check_MK.
13
+# The official homepage is at http://mathias-kettner.de/check_mk.
14
+#
15
+# check_mk is free software;  you can redistribute it and/or modify it
16
+# under the  terms of the  GNU General Public License  as published by
17
+# the Free Software Foundation in version 2.  check_mk is  distributed
18
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
19
+# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
20
+# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
21
+# tails. You should have  received  a copy of the  GNU  General Public
22
+# License along with GNU Make; see the file  COPYING.  If  not,  write
23
+# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
24
+# Boston, MA 02110-1301 USA.
25
+
26
+su - griduser -c "asmcmd $@"

+ 34
- 0
ansible/roles/elnappo.check_mk_agent/files/plugins/db2_mem View File

@@ -0,0 +1,34 @@
1
+#!/bin/sh
2
+# +------------------------------------------------------------------+
3
+# |             ____ _               _        __  __ _  __           |
4
+# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
5
+# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
6
+# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
7
+# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
8
+# |                                                                  |
9
+# | Copyright Mathias Kettner 2014             mk@mathias-kettner.de |
10
+# +------------------------------------------------------------------+
11
+#
12
+# This file is part of Check_MK.
13
+# The official homepage is at http://mathias-kettner.de/check_mk.
14
+#
15
+# check_mk is free software;  you can redistribute it and/or modify it
16
+# under the  terms of the  GNU General Public License  as published by
17
+# the Free Software Foundation in version 2.  check_mk is  distributed
18
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
19
+# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
20
+# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
21
+# tails. You should have  received  a copy of the  GNU  General Public
22
+# License along with GNU Make; see the file  COPYING.  If  not,  write
23
+# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
24
+# Boston, MA 02110-1301 USA.
25
+
26
+INSTANCES=$(ps -ef | grep db2sysc | awk '{print $1}' | sort -u | grep -v root)
27
+
28
+if [ "$INSTANCES" ] ; then
29
+    echo "<<<db2_mem>>>"
30
+    for INSTANCE in $INSTANCES; do
31
+        echo "Instance $INSTANCE"
32
+        su - $INSTANCE -c "db2pd -dbptnmem " | egrep '(Memory Limit|HWM usage)'
33
+    done
34
+fi

+ 48
- 0
ansible/roles/elnappo.check_mk_agent/files/plugins/dnsclient View File

@@ -0,0 +1,48 @@
1
+#!/bin/sh
2
+# +------------------------------------------------------------------+
3
+# |             ____ _               _        __  __ _  __           |
4
+# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
5
+# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
6
+# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
7
+# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
8
+# |                                                                  |
9
+# | Copyright Mathias Kettner 2014             mk@mathias-kettner.de |
10
+# +------------------------------------------------------------------+
11
+#
12
+# This file is part of Check_MK.
13
+# The official homepage is at http://mathias-kettner.de/check_mk.
14
+#
15
+# check_mk is free software;  you can redistribute it and/or modify it
16
+# under the  terms of the  GNU General Public License  as published by
17
+# the Free Software Foundation in version 2.  check_mk is  distributed
18
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
19
+# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
20
+# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
21
+# tails. You should have  received  a copy of the  GNU  General Public
22
+# License along with GNU Make; see the file  COPYING.  If  not,  write
23
+# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
24
+# Boston, MA 02110-1301 USA.
25
+
26
+# This check can be used to test the name resolution of a given host
27
+# address using the local resolver of the system this script is
28
+# running on.
29
+
30
+HOSTADDRESSES=mathias-kettner.de
31
+
32
+if [ -e $MK_CONFDIR/dnsclient.cfg ] ; then
33
+    . $MK_CONFDIR/dnsclient.cfg
34
+fi
35
+
36
+echo "<<<mrpe>>>"
37
+for HOSTADDRESS in $HOSTADDRESSES
38
+do
39
+    ADDRESSES=`nslookup $HOSTADDRESS | sed -n -e 1,3d -e '/^Address: *\(.*\)$/s//\1/p'`
40
+    if [ ! "$ADDRESSES" ] ; then
41
+        STATE=2
42
+        OUTPUT="CRIT - $HOSTADDRESS could not be resolved"
43
+    else
44
+        STATE=0
45
+        OUTPUT="OK - $HOSTADDRESS resolved into $ADDRESSES"
46
+    fi
47
+    echo Resolve_$HOSTADDRESS $STATE $OUTPUT
48
+done

+ 92
- 0
ansible/roles/elnappo.check_mk_agent/files/plugins/hpux_lunstats View File

@@ -0,0 +1,92 @@
1
+#!/usr/bin/ksh
2
+# Monitor status of LUNs on HP-UX
3
+# +------------------------------------------------------------------+
4
+# |             ____ _               _        __  __ _  __           |
5
+# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
6
+# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
7
+# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
8
+# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
9
+# |                                                                  |
10
+# | Copyright Mathias Kettner 2014             mk@mathias-kettner.de |
11
+# +------------------------------------------------------------------+
12
+#
13
+# This file is part of Check_MK.
14
+# The official homepage is at http://mathias-kettner.de/check_mk.
15
+#
16
+# check_mk is free software;  you can redistribute it and/or modify it
17
+# under the  terms of the  GNU General Public License  as published by
18
+# the Free Software Foundation in version 2.  check_mk is  distributed
19
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
20
+# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
21
+# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
22
+# tails. You should have  received  a copy of the  GNU  General Public
23
+# License along with GNU Make; see the file  COPYING.  If  not,  write
24
+# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
25
+# Boston, MA 02110-1301 USA.
26
+
27
+# Put this file into /usr/lib/check_mk_agent/plugins. Then
28
+# reinventorize your host.
29
+# Actually querying these stats is quite slow since they freshly update
30
+# on each call. If you have a few 1000 luns then this will not work.
31
+
32
+get_stats()
33
+{
34
+    scsimgr get_stat -D $LUN | tr '\=' ':' | grep -e 'STATISTICS FOR LUN'  -e 'Bytes' -e 'Total I/Os processed' -e 'I/O failure' -e 'IO failures due
35
+to'
36
+    return $?
37
+}
38
+
39
+
40
+# Ex:
41
+#LUN PATH INFORMATION FOR LUN : /dev/pt/pt2
42
+#World Wide Identifier(WWID) =
43
+#LUN PATH INFORMATION FOR LUN : /dev/rdisk/disk5
44
+#World Wide Identifier(WWID) = 0x60a98000572d44745634645076556357
45
+#LUN PATH INFORMATION FOR LUN : /dev/rdisk/disk6
46
+
47
+get_lun_map()
48
+{
49
+scsimgr lun_map | egrep '^[[:space:]]*(LUN PATH|World Wide Identifier)' | tr '\=' ':'
50
+}
51
+
52
+
53
+main()
54
+{
55
+get_lun_map | while read line ; do
56
+    descr=$(echo $line | awk -F: '{print $1}')
57
+    val=$(  echo $line | awk -F: '{print $2}')
58
+    case $descr in
59
+      LUN*)
60
+          if echo $val | grep /dev/rdisk 1>/dev/null; then
61
+              DMP=yes
62
+              LUN=$val
63
+          else
64
+              DMP=no
65
+              unset LUN
66
+          fi
67
+      ;;
68
+      World*)
69
+          if [ $DMP = "yes" ]; then
70
+              echo "WWID: $val"
71
+              get_stats $LUN
72
+          fi
73
+      ;;
74
+      *)
75
+          echo "Fehler:"
76
+          echo $line
77
+          echo $descr
78
+          echo $val
79
+          sleep 1
80
+      ;;
81
+    esac
82
+done
83
+}
84
+
85
+
86
+
87
+# Verify the system is using new multipath device model.
88
+if [ -d /dev/rdisk ] && [ -d /dev/disk ]; then
89
+    echo '<<<hpux_lunstats:sep(58)>>>'
90
+    main
91
+fi
92
+

+ 49
- 0
ansible/roles/elnappo.check_mk_agent/files/plugins/hpux_statgrab View File

@@ -0,0 +1,49 @@
1
+#!/bin/sh
2
+# +------------------------------------------------------------------+
3
+# |             ____ _               _        __  __ _  __           |
4
+# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
5
+# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
6
+# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
7
+# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
8
+# |                                                                  |
9
+# | Copyright Mathias Kettner 2014             mk@mathias-kettner.de |
10
+# +------------------------------------------------------------------+
11
+#
12
+# This file is part of Check_MK.
13
+# The official homepage is at http://mathias-kettner.de/check_mk.
14
+#
15
+# check_mk is free software;  you can redistribute it and/or modify it
16
+# under the  terms of the  GNU General Public License  as published by
17
+# the Free Software Foundation in version 2.  check_mk is  distributed
18
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
19
+# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
20
+# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
21
+# tails. You should have  received  a copy of the  GNU  General Public
22
+# License along with GNU Make; see the file  COPYING.  If  not,  write
23
+# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
24
+# Boston, MA 02110-1301 USA.
25
+
26
+# this is for users who compiled statgrab on hp-ux.
27
+# note you'll need a 0.18+ version, from their github page at
28
+# https://github.com/i-scream/libstatgrab
29
+# flags used for compiling - disable documentation, examples and set*id
30
+
31
+
32
+if which statgrab > /dev/null ; then
33
+    if statgrab const. cpu. general. mem. page. proc. swap. user. > /tmp/statgrab.$$ 2>/dev/null
34
+        then
35
+        for s in proc cpu page
36
+        do
37
+            echo "<<<statgrab_$s>>>"
38
+            cat /tmp/statgrab.$$ | grep "^$s\." | cut -d. -f2-99 | sed 's/ *= */ /'
39
+        done
40
+
41
+        echo '<<<statgrab_mem>>>'
42
+        cat /tmp/statgrab.$$ | egrep "^(swap|mem)\." | sed 's/ *= */ /'
43
+
44
+        echo '<<<uptime>>>'
45
+        cat /tmp/statgrab.$$ | egrep "^general\.uptime" | sed 's/.* //'
46
+
47
+    fi
48
+    [ -f /tmp/statgrab.$$ ] && rm -f /tmp/statgrab.$$
49
+fi

+ 85
- 0
ansible/roles/elnappo.check_mk_agent/files/plugins/isc_dhcpd View File

@@ -0,0 +1,85 @@
1
+#!/usr/bin/python
2
+# Monitor leases if ISC-DHCPD
3
+
4
+import os, sys, time, re, calendar
5
+
6
+conf_file = None
7
+for path in [ '/etc/dhcpd.conf', '/etc/dhcp/dhcpd.conf', '/usr/local/etc/dhcpd.conf' ]:
8
+    if os.path.exists(path):
9
+        conf_file = path
10
+        break
11
+
12
+leases_file = None
13
+for path in [
14
+        '/var/lib/dhcp/db/dhcpd.leases',
15
+        '/var/lib/dhcp/dhcpd.leases',
16
+        '/var/lib/dhcpd/dhcpd.leases', # CentOS
17
+    ]:
18
+    if os.path.exists(path):
19
+        leases_file = path
20
+        break
21
+
22
+# If no configuration and leases are found, we assume that
23
+# no dhcpd is running.
24
+if not conf_file or not leases_file:
25
+    sys.exit(0)
26
+
27
+pidof_dhcpd = os.popen("pidof dhcpd").read().strip()
28
+sys.stdout.write('<<<isc_dhcpd>>>\n[general]\nPID: %s\n' % pidof_dhcpd)
29
+
30
+sys.stdout.write('[pools]\n')
31
+
32
+
33
+def parse_config(filename):
34
+    for line in file(filename):
35
+        line = line.strip()
36
+        if line.startswith("include"):
37
+            included_file = re.search('include\s+"(.*)"', line).group(1)
38
+            parse_config(included_file)
39
+        elif line.startswith("range"):
40
+            sys.stdout.write(line[5:].strip("\t ;") + "\n")
41
+
42
+parse_config(conf_file)
43
+
44
+
45
+# lease 10.1.1.81 {
46
+#   starts 3 2015/09/09 11:42:20;
47
+#   ends 3 2015/09/09 19:42:20;
48
+#   tstp 3 2015/09/09 19:42:20;
49
+#   cltt 3 2015/09/09 11:42:20;
50
+#   binding state free;
51
+#   hardware ethernet a4:5e:60:de:1f:c3;
52
+#   uid "\001\244^`\336\037\303";
53
+#   set ddns-txt = "318c69bae8aeae6f8c723e96de933c7149";
54
+#   set ddns-fwd-name = "Sebastians-MBP.dhcp.mathias-kettner.de";
55
+# }
56
+
57
+sys.stdout.write('[leases]\n')
58
+now = time.time()
59
+ip_address = None
60
+binding_state = None
61
+seen_addresses = set()
62
+for line in file(leases_file):
63
+    parts = line.strip().rstrip(";").split()
64
+    if not parts:
65
+        continue
66
+
67
+    if parts[0] == "lease":
68
+        ip_address = parts[1]
69
+    elif parts[0] == "ends":
70
+        if parts[1] != "never":
71
+            ends_date_string = parts[2] + " " + parts[3]
72
+            ends_date = calendar.timegm(time.strptime(ends_date_string, "%Y/%m/%d %H:%M:%S"))
73
+            if ends_date < now:
74
+                ip_address = None # skip this address, this lease is outdated
75
+
76
+    elif parts[0] == "binding" and parts[1] == "state":
77
+        binding_state = parts[2]
78
+
79
+    elif parts[0] == "}":
80
+        if ip_address and binding_state == "active" and ip_address not in seen_addresses:
81
+            sys.stdout.write("%s\n" % ip_address)
82
+            seen_addresses.add(ip_address)
83
+        ip_address = None
84
+        binding_state = None
85
+

+ 52
- 0
ansible/roles/elnappo.check_mk_agent/files/plugins/jar_signature View File

@@ -0,0 +1,52 @@
1
+#!/bin/bash
2
+# +------------------------------------------------------------------+
3
+# |             ____ _               _        __  __ _  __           |
4
+# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
5
+# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
6
+# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
7
+# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
8
+# |                                                                  |
9
+# | Copyright Mathias Kettner 2014             mk@mathias-kettner.de |
10
+# +------------------------------------------------------------------+
11
+#
12
+# This file is part of Check_MK.
13
+# The official homepage is at http://mathias-kettner.de/check_mk.
14
+#
15
+# check_mk is free software;  you can redistribute it and/or modify it
16
+# under the  terms of the  GNU General Public License  as published by
17
+# the Free Software Foundation in version 2.  check_mk is  distributed
18
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
19
+# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
20
+# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
21
+# tails. You should have  received  a copy of the  GNU  General Public
22
+# License along with GNU Make; see the file  COPYING.  If  not,  write
23
+# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
24
+# Boston, MA 02110-1301 USA.
25
+
26
+# This agent uses the program "jarsigner" to read ssl certificate
27
+# information of jar files and outputs the information to stdout
28
+# for the Check_MK check.
29
+# We assume that all files in the jar archive are signed with the
30
+# same certificate. So we only deal with the last signed file here.
31
+
32
+JAVA_HOME=/home/oracle/bin/jdk_latest_version
33
+JAR_PATH=/home/oracle/fmw/11gR2/as_1/forms/java/*.jar
34
+
35
+# Let user override these defaults in a configuration file
36
+if [ -e $MK_CONFDIR/jar_signature.cfg ] ; then
37
+    . $MK_CONFDIR/jar_signature.cfg
38
+fi
39
+
40
+PATH=$JAVA_HOME/bin:$PATH
41
+
42
+echo "<<<jar_signature>>>"
43
+for JAR in $JAR_PATH; do
44
+    if [ -e "$JAR" ] ; then # avoid entry for '*.jar'
45
+        echo "[[[${JAR##*/}]]]"
46
+        OUTPUT=$(jarsigner -verify -verbose -certs "$JAR")
47
+        LINE=$(echo "$OUTPUT" | grep -n ^s | tail -n1 | cut -d: -f1)
48
+        echo "$(echo "$OUTPUT" | tail -n +$LINE)"
49
+        echo
50
+    fi
51
+done
52
+

+ 38
- 0
ansible/roles/elnappo.check_mk_agent/files/plugins/kaspersky_av View File

@@ -0,0 +1,38 @@
1
+#!/bin/sh
2
+# +------------------------------------------------------------------+
3
+# |             ____ _               _        __  __ _  __           |
4
+# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
5
+# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
6
+# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
7
+# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
8
+# |                                                                  |
9
+# | Copyright Mathias Kettner 2014             mk@mathias-kettner.de |
10
+# +------------------------------------------------------------------+
11
+#
12
+# This file is part of Check_MK.
13
+# The official homepage is at http://mathias-kettner.de/check_mk.
14
+#
15
+# check_mk is free software;  you can redistribute it and/or modify it
16
+# under the  terms of the  GNU General Public License  as published by
17
+# the Free Software Foundation in version 2.  check_mk is  distributed
18
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
19
+# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
20
+# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
21
+# tails. You should have  received  a copy of the  GNU  General Public
22
+# License along with GNU Make; see the file  COPYING.  If  not,  write
23
+# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
24
+# Boston, MA 02110-1301 USA.
25
+
26
+if [ -f /opt/kaspersky/kav4fs/bin/kav4fs-control ]
27
+then
28
+   echo "<<<kaspersky_av_updates:sep(58)>>>"
29
+   /opt/kaspersky/kav4fs/bin/kav4fs-control --get-stat Update
30
+
31
+  echo "<<<kaspersky_av_quarantine:sep(58)>>>"
32
+  /opt/kaspersky/kav4fs/bin/kav4fs-control -Q --get-stat
33
+
34
+  echo "<<<kaspersky_av_tasks>>>"
35
+  /opt/kaspersky/kav4fs/bin/kav4fs-control --get-task-list
36
+
37
+fi
38
+

+ 40
- 0
ansible/roles/elnappo.check_mk_agent/files/plugins/lnx_quota View File

@@ -0,0 +1,40 @@
1
+#!/bin/bash
2
+# +------------------------------------------------------------------+
3
+# |             ____ _               _        __  __ _  __           |
4
+# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
5
+# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
6
+# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
7
+# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
8
+# |                                                                  |
9
+# | Copyright Mathias Kettner 2014             mk@mathias-kettner.de |
10
+# +------------------------------------------------------------------+
11
+#
12
+# This file is part of Check_MK.
13
+# The official homepage is at http://mathias-kettner.de/check_mk.
14
+#
15
+# check_mk is free software;  you can redistribute it and/or modify it
16
+# under the  terms of the  GNU General Public License  as published by
17
+# the Free Software Foundation in version 2.  check_mk is  distributed
18
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
19
+# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
20
+# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
21
+# tails. You should have  received  a copy of the  GNU  General Public
22
+# License along with GNU Make; see the file  COPYING.  If  not,  write
23
+# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
24
+# Boston, MA 02110-1301 USA.
25
+
26
+if type repquota >/dev/null ; then
27
+    echo "<<<lnx_quota>>>"
28
+
29
+    # User Quota
30
+    for VOL in $(grep -E usr[j]?quota /etc/fstab | tr -s '\t' ' ' | cut -d' ' -f2); do
31
+        echo "[[[usr:$VOL]]]"
32
+        repquota -up $VOL | tail -n +6 | head -n -2
33
+    done
34
+
35
+    # Group Quota
36
+    for VOL in $(grep -E grp[j]?quota /etc/fstab | tr -s '\t' ' ' | cut -d' ' -f2); do
37
+        echo "[[[grp:$VOL]]]"
38
+        repquota -gp $VOL | tail -n +6 | head -n -2
39
+    done
40
+fi

+ 9
- 0
ansible/roles/elnappo.check_mk_agent/files/plugins/lvm View File

@@ -0,0 +1,9 @@
1
+#!/bin/bash
2
+echo "<<<lvm_vgs>>>"
3
+vgs --units b --nosuffix --noheadings --separator '	'
4
+
5
+echo "<<<lvm_lvs:sep(124)>>>"
6
+lvs --units b --nosuffix --noheadings --separator '|'
7
+
8
+#echo "<<<lvm_pvs>>>"
9
+#pvs --units b --nosuffix --noheadings --separator '	'

+ 55
- 0
ansible/roles/elnappo.check_mk_agent/files/plugins/mailman_lists View File

@@ -0,0 +1,55 @@
1
+#!/usr/bin/python
2
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
3
+# +------------------------------------------------------------------+
4
+# |             ____ _               _        __  __ _  __           |
5
+# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
6
+# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
7
+# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
8
+# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
9
+# |                                                                  |
10
+# | Copyright Mathias Kettner 2014             mk@mathias-kettner.de |
11
+# +------------------------------------------------------------------+
12
+#
13
+# This file is part of Check_MK.
14
+# The official homepage is at http://mathias-kettner.de/check_mk.
15
+#
16
+# check_mk is free software;  you can redistribute it and/or modify it
17
+# under the  terms of the  GNU General Public License  as published by
18
+# the Free Software Foundation in version 2.  check_mk is  distributed
19
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
20
+# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
21
+# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
22
+# tails. You should have  received  a copy of the  GNU  General Public
23
+# License along with GNU Make; see the file  COPYING.  If  not,  write
24
+# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
25
+# Boston, MA 02110-1301 USA.
26
+
27
+# This Check_MK-Agent plugin gathers information about mailinglists hosted
28
+# by the local mailman instance.
29
+
30
+# Needed if you have located your mailman python modules not in default
31
+# python module paths
32
+import sys
33
+sys.path.append("/usr/local/mailman")
34
+sys.path.append("/usr/lib/mailman")
35
+
36
+# Set to True to filter out all "hidden" mailinglists
37
+only_advertised = True
38
+
39
+from Mailman import Utils, MailList # pylint: disable=import-error
40
+
41
+# 1. list memberships
42
+sys.stdout.write('<<<mailman_lists>>>\n')
43
+total_members = set([])
44
+for name in sorted(Utils.list_names()):
45
+    mlist = MailList.MailList(name, lock=0)
46
+    if only_advertised and not mlist.advertised:
47
+        continue
48
+
49
+    rmembers = mlist.getRegularMemberKeys()
50
+    dmembers = mlist.getDigestMemberKeys()
51
+    members = rmembers + dmembers
52
+    total_members.update(members)
53
+
54
+    sys.stdout.write('%s %d\n' % (name, len(members)))
55
+sys.stdout.write('TOTAL %d\n' % len(total_members))

+ 65
- 0
ansible/roles/elnappo.check_mk_agent/files/plugins/mk_apt View File

@@ -0,0 +1,65 @@
1
+#!/bin/bash
2
+# Check for APT updates (Debian, Ubuntu)
3
+# +------------------------------------------------------------------+
4
+# |             ____ _               _        __  __ _  __           |
5
+# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
6
+# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
7
+# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
8
+# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
9
+# |                                                                  |
10
+# | Copyright Mathias Kettner 2014             mk@mathias-kettner.de |
11
+# +------------------------------------------------------------------+
12
+#
13
+# This file is part of Check_MK.
14
+# The official homepage is at http://mathias-kettner.de/check_mk.
15
+#
16
+# check_mk is free software;  you can redistribute it and/or modify it
17
+# under the  terms of the  GNU General Public License  as published by
18
+# the Free Software Foundation in version 2.  check_mk is  distributed
19
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
20
+# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
21
+# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
22
+# tails. You should have  received  a copy of the  GNU  General Public
23
+# License along with GNU Make; see the file  COPYING.  If  not,  write
24
+# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
25
+# Boston, MA 02110-1301 USA.
26
+
27
+# TODO:
28
+# Einstellungen:
29
+# - upgrade oder dist-upgrade
30
+# - vorher ein update machen
31
+# Bakery:
32
+# - Bakelet anlegen
33
+# - Async-Zeit einstellbar machen und das Ding immer async laufen lassen
34
+# Check programmieren:
35
+#   * Schwellwerte auf Anzahlen
36
+#   * Regexen auf Pakete, die zu CRIT/WARN führen
37
+# - Graph malen mit zwei Kurven
38
+
39
+# This variable can either be "upgrade" or "dist-upgrade"
40
+UPGRADE=upgrade
41
+DO_UPDATE=yes
42
+
43
+
44
+function check_apt_update {
45
+    if [ "$DO_UPDATE" = yes ] ; then
46
+        # NOTE: Even with -qq, apt-get update can output several lines to
47
+        # stderr, e.g.:
48
+        #
49
+        # W: There is no public key available for the following key IDs:
50
+        # 1397BC53640DB551
51
+        apt-get update -qq 2> /dev/null
52
+    fi
53
+    apt-get -o 'Debug::NoLocking=true' -o 'APT::Get::Show-User-Simulation-Note=false' -s -qq "$UPGRADE" | grep -v '^Conf'
54
+}
55
+
56
+
57
+if type apt-get > /dev/null ; then
58
+    echo '<<<apt:sep(0)>>>'
59
+    out=$(check_apt_update)
60
+    if [ -z "$out" ]; then
61
+        echo "No updates pending for installation"
62
+    else
63
+        echo "$out"
64
+    fi
65
+fi

+ 44
- 0
ansible/roles/elnappo.check_mk_agent/files/plugins/mk_ceph View File

@@ -0,0 +1,44 @@
1
+#!/bin/bash
2
+# Check for APT updates (Debian, Ubuntu)
3
+# +------------------------------------------------------------------+
4
+# |             ____ _               _        __  __ _  __           |
5
+# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
6
+# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
7
+# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
8
+# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
9
+# |                                                                  |
10
+# | Copyright Mathias Kettner 2017             mk@mathias-kettner.de |
11
+# +------------------------------------------------------------------+
12
+#
13
+# This file is part of Check_MK.
14
+# The official homepage is at http://mathias-kettner.de/check_mk.
15
+#
16
+# check_mk is free software;  you can redistribute it and/or modify it
17
+# under the  terms of the  GNU General Public License  as published by
18
+# the Free Software Foundation in version 2.  check_mk is  distributed
19
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
20
+# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
21
+# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
22
+# tails. You should have  received  a copy of the  GNU  General Public
23
+# License along with GNU Make; see the file  COPYING.  If  not,  write
24
+# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
25
+# Boston, MA 02110-1301 USA.
26
+
27
+
28
+# Config file must contain:
29
+# USER=client.admin
30
+# KEYRING=/etc/ceph/ceph.client.admin.keyring
31
+
32
+
33
+if [ -e "$MK_CONFDIR/ceph.cfg" ]; then
34
+    . $MK_CONFDIR/ceph.cfg
35
+fi
36
+
37
+
38
+if [ ! -z "$USER" ] && [ ! -z "$KEYRING" ]; then
39
+    CEPH_CMD="ceph -n $USER --keyring=$KEYRING"
40
+    echo "<<<ceph_status>>>"
41
+    $CEPH_CMD -s -f json-pretty
42
+    echo "<<<ceph_df>>>"
43
+    $CEPH_CMD df detail
44
+fi

+ 54
- 0
ansible/roles/elnappo.check_mk_agent/files/plugins/mk_cups_queues View File

@@ -0,0 +1,54 @@
1
+#!/bin/bash
2
+# +------------------------------------------------------------------+
3
+# |             ____ _               _        __  __ _  __           |
4
+# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
5
+# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
6
+# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
7
+# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
8
+# |                                                                  |
9
+# | Copyright Mathias Kettner 2017             mk@mathias-kettner.de |
10
+# +------------------------------------------------------------------+
11
+#
12
+# This file is part of Check_MK.
13
+# The official homepage is at http://mathias-kettner.de/check_mk.
14
+#
15
+# check_mk is free software;  you can redistribute it and/or modify it
16
+# under the  terms of the  GNU General Public License  as published by
17
+# the Free Software Foundation in version 2.  check_mk is  distributed
18
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
19
+# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
20
+# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
21
+# tails. You should have  received  a copy of the  GNU  General Public
22
+# License along with GNU Make; see the file  COPYING.  If  not,  write
23
+# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
24
+# Boston, MA 02110-1301 USA.
25
+
26
+if type lpstat > /dev/null 2>&1 ; then
27
+    export LC_TIME="en_US.UTF-8"
28
+    echo "<<<cups_queues>>>"
29
+    CPRINTCONF=/etc/cups/printers.conf
30
+    if  [ -r "$CPRINTCONF" ] ; then
31
+        LOCAL_PRINTERS=$(grep -E "<(Default)?Printer .*>" $CPRINTCONF | awk '{print $2}' | sed -e 's/>//')
32
+        lpstat -p | while read LINE
33
+        do
34
+            PRINTER=$(echo "$LINE" | awk '{print $2}')
35
+            if echo "$LOCAL_PRINTERS" | grep -q "$PRINTER"; then
36
+                echo "$LINE"
37
+            fi
38
+        done
39
+        echo '---'
40
+        lpstat -o | while read LINE
41
+        do
42
+            PRINTER=${LINE%%-*}
43
+            if echo "$LOCAL_PRINTERS" | grep -q "$PRINTER"; then
44
+                echo "$LINE"
45
+            fi
46
+        done
47
+    else
48
+        PRINTER=$(lpstat -p)
49
+        echo "$PRINTER"
50
+        echo '---'
51
+        QUEUE=$(lpstat -o | sort)
52
+        echo "$QUEUE"
53
+    fi
54
+fi

+ 231
- 0
ansible/roles/elnappo.check_mk_agent/files/plugins/mk_db2.aix View File

@@ -0,0 +1,231 @@
1
+#!/usr/bin/ksh
2
+# Monitor DB/2 databases on AIX
3
+# $HOME/sqllib/db2profile
4
+
5
+# This script can be called in two ways
6
+# Without any arguments:
7
+#   Checks if cache of the instances is up to date and starts the
8
+#   command 'mk_db.aix query {instance}' if applicable
9
+#   If its outdated the script calls itself with the argument 'query'
10
+# With 'query {instance}' as argument:
11
+#   Does the actual queries to the db2 instance and writes this info
12
+#   into the cache file
13
+# Each instance has its own cache file and all of them are filled in parallel
14
+
15
+if [ ! "$MK_CONFDIR" ] ; then
16
+    echo "MK_CONFDIR not set!" >&2
17
+    exit 1
18
+fi
19
+
20
+if [ ! "$MK_VARDIR" ] ; then
21
+    export MK_VARDIR=$MK_CONFDIR
22
+fi
23
+
24
+function waitmax
25
+{
26
+   TIMEOUT=${1}0
27
+   SIGNAL=9
28
+   shift
29
+
30
+   # Run command in background
31
+   if [ "${#}" -ge 1 ] ; then
32
+      ksh -c "$*" &
33
+   else
34
+      TEST=$(cat)
35
+      ksh -c "$TEST" &
36
+   fi
37
+
38
+   PID=$!
39
+
40
+   # Wait for termination within TIMOUT seconds
41
+   while [ $TIMEOUT -gt 0 ]
42
+   do
43
+       TIMEOUT=$((TIMEOUT - 1))
44
+       if [ ! -e /proc/$PID ] ; then
45
+           return 0
46
+       fi
47
+       perl -e "select(undef, undef, undef, 0.1);"
48
+   done
49
+
50
+   # Process did not terminate in time. Kill and
51
+   # return with an error
52
+   kill -9 $PID
53
+   return 255
54
+}
55
+
56
+function query_instance {
57
+    INSTANCE=$1
58
+    # find home directory
59
+    HOMEDIR=$(grep "^$INSTANCE" /etc/passwd | awk -F: '{print $6}' | grep "$INSTANCE$")
60
+    NOW=$(perl -e "print time();")
61
+
62
+    waitmax 200 << WAITMAX
63
+    su $INSTANCE << EOF
64
+
65
+    if [ ! -f $HOMEDIR/sqllib/db2profile ] ;
66
+    then
67
+        exit 0
68
+    fi
69
+
70
+    . $HOMEDIR/sqllib/db2profile >/dev/null 2>&1 ;
71
+
72
+
73
+    function compare_version_greater_equal {
74
+        GREATER_ONE=\\\$(echo "\\\$1 \\\$2" | awk "{if (\\\$1 >= \\\$2) print \\\$1; else print \\\$2}")
75
+        if [ \\\$GREATER_ONE == \\\$1 ] ; then
76
+            return 0
77
+        else
78
+           return 1
79
+        fi
80
+    }
81
+
82
+    echo '<<<db2_version:sep(1)>>>'
83
+    DBVERSION=\\\$(db2 get snapshot for dbm | grep -e 'Product name' -e 'Service level' | awk -v FS='=' '{print \\\$2}' | sed 'N;s/\n/,/g' | sed 's/ //g')
84
+    echo $INSTANCE \\\$DBVERSION
85
+    VERSION_NUMBER=\\\$(echo \\\$DBVERSION | sed  -e 's/DB2v\\\(.*\),.*/\\\1/' | awk -v FS="." '{print \\\$1"."\\\$2}')
86
+
87
+    DBS=\\\$(db2 list database directory on $HOMEDIR | grep 'Database name' | awk '{ print \\\$NF }')
88
+
89
+    GET_PORT=1
90
+    DB_PORT='port 0'
91
+    for DB in \\\$DBS; do
92
+            db2 connect to \\\$DB > /dev/null;
93
+            if [ $? -nq 0 ] ; then
94
+                exit 1
95
+            fi
96
+
97
+            if [ 1 -eq \\\$GET_PORT ] ; then
98
+                # Each database in an instance has the same port information
99
+                db2_tcp_service=\\\$(db2 -x get dbm cfg | grep $INSTANCE | grep "TCP/IP Service" | awk -v FS='=' '{print \\\$2}'|tr -d ' ')
100
+                if ( grep \\\$db2_tcp_service /etc/services | grep -q "^\\\$db2_tcp_service " ); then
101
+                    DB_PORT='port '\\\$(grep \\\$db2_tcp_service /etc/services | grep "^\\\$db2_tcp_service " | awk '{print \\\$2}' | awk -v FS="/" '{print \\\$1}')
102
+                fi
103
+                GET_PORT=0
104
+            fi
105
+
106
+            echo "<<<db2_tablespaces>>>"
107
+            echo "[[[$INSTANCE:\\\$DB]]]"
108
+            db2 "SELECT tbsp_name, tbsp_type, tbsp_state, tbsp_usable_size_kb, tbsp_total_size_kb, tbsp_used_size_kb, tbsp_free_size_kb FROM sysibmadm.tbsp_utilization WHERE tbsp_type = 'DMS' UNION ALL SELECT tu.tbsp_name, tu.tbsp_type, tu.tbsp_state, tu.tbsp_usable_size_kb, tu.tbsp_total_size_kb, tu.tbsp_used_size_kb, (cu.fs_total_size_kb - cu.fs_used_size_kb) AS tbsp_free_size_kb FROM sysibmadm.tbsp_utilization tu INNER JOIN ( SELECT tbsp_id, 1 AS fs_total_size_kb, 0 AS fs_used_size_kb FROM sysibmadm.container_utilization WHERE (fs_total_size_kb IS NULL OR fs_used_size_kb IS NULL) GROUP BY tbsp_id) cu ON (tu.tbsp_type = 'SMS' AND tu.tbsp_id = cu.tbsp_id) UNION ALL SELECT tu.tbsp_name, tu.tbsp_type, tu.tbsp_state, tu.tbsp_usable_size_kb, tu.tbsp_total_size_kb, tu.tbsp_used_size_kb, (cu.fs_total_size_kb - cu.fs_used_size_kb) AS tbsp_free_size_kb FROM sysibmadm.tbsp_utilization tu INNER JOIN ( SELECT tbsp_id, SUM(fs_total_size_kb) AS fs_total_size_kb, SUM(fs_used_size_kb) AS fs_used_size_kb FROM sysibmadm.container_utilization WHERE (fs_total_size_kb IS NOT NULL AND fs_used_size_kb IS NOT NULL) GROUP BY tbsp_id) cu ON (tu.tbsp_type = 'SMS' AND tu.tbsp_id = cu.tbsp_id)" | awk '{print \\\$1" "\\\$2" "\\\$3" "\\\$4" "\\\$5" "\\\$6" "\\\$7}' | sed -e '/^[ ]*$/d' -e '/^-/d' -e '/selected/d'
109
+
110
+            echo "<<<db2_counters>>>"
111
+            echo "TIMESTAMP $NOW"
112
+            cat \\\$(db2 get dbm cfg|grep "Default database path"|awk -v FS="=" '{print \\\$2"/sqllib/db2nodes.cfg"}'|tr -d ' ') | sed "s/\(.*\)/$INSTANCE:\\\$DB node \1/"
113
+            db2 -x "SELECT deadlocks from sysibmadm.snapdb" | tr -d ' ' | sed "s/\(.*\)/$INSTANCE:\\\$DB deadlocks \1/"
114
+            db2 -x "SELECT lock_waits from sysibmadm.snapdb" | tr -d ' ' | sed "s/\(.*\)/$INSTANCE:\\\$DB lockwaits \1/"
115
+            db2 -x "SELECT sort_overflows from sysibmadm.snapdb" | tr -d ' ' | sed "s/\(.*\)/$INSTANCE:\\\$DB sortoverflows \1/"
116
+
117
+            echo "<<<db2_logsizes>>>"
118
+            echo "[[[$INSTANCE:\\\$DB]]]"
119
+            echo "TIMESTAMP $NOW"
120
+            cat \\\$(db2 get dbm cfg|grep "Default database path"|awk -v FS="=" '{print \\\$2"/sqllib/db2nodes.cfg"}'|tr -d ' ') | sed 's/\(.*\)/node \1/'
121
+            db2 -x "SELECT 'usedspace', total_log_used from sysibmadm.snapdb" | awk '{print \\\$1" "\\\$2}'
122
+            db2 -x "SELECT NAME, VALUE FROM SYSIBMADM.DBCFG WHERE NAME IN ('logfilsiz','logprimary','logsecond')"| awk '{print \\\$1" "\\\$2}'
123
+
124
+            echo "<<<db2_connections>>>"
125
+            echo "[[[$INSTANCE:\\\$DB]]]"
126
+            echo \\\$DB_PORT
127
+            echo "connections " | tr -d '\n'
128
+            db2 list applications | grep -v Auth | grep -v Name | sed -e '/^$/d' | wc -l | tr -d ' '
129
+            # TODO: the time command seems to be broken and outputs 1 second steps
130
+            ksh -c "time db2 connect to \\\$DB > /dev/null" 2>&1 | grep real | awk '{print "latency "\\\$2}'| sed -e 's/m/:/' -e 's/s//'
131
+
132
+            echo "<<<db2_bp_hitratios>>>"
133
+            echo "[[[$INSTANCE:\\\$DB]]]"
134
+            cat \\\$(db2 get dbm cfg|grep "Default database path"|awk -v FS="=" '{print \\\$2"/sqllib/db2nodes.cfg"}'|tr -d ' ') | sed "s/\(.*\)/node \1/"
135
+            db2 "SELECT SUBSTR(BP_NAME,1,14) AS BP_NAME, TOTAL_HIT_RATIO_PERCENT, DATA_HIT_RATIO_PERCENT, INDEX_HIT_RATIO_PERCENT, XDA_HIT_RATIO_PERCENT FROM SYSIBMADM.BP_HITRATIO" | grep -v "selected." | sed -e '/^$/d' -e '/^-/d'
136
+
137
+            echo "<<<db2_sort_overflow>>>"
138
+            echo "[[[$INSTANCE:\\\$DB]]]"
139
+            db2 -x "get snapshot for database on \\\$DB" | grep -e "^Total sorts" -e "^Sort overflows" | tr -d '='
140
+
141
+            echo "<<<db2_backup>>>"
142
+            echo "[[[$INSTANCE:\\\$DB]]]"
143
+            if compare_version_greater_equal \\\$VERSION_NUMBER 10.5; then
144
+                # MON_GET_DATBASE(-2) gets information of all active members
145
+                db2 -x "select LAST_BACKUP from TABLE (MON_GET_DATABASE(-2))" | grep -v "selected." | tail -n 1
146
+            else
147
+                db2 -x "select SQLM_ELM_LAST_BACKUP from table(SNAPSHOT_DATABASE( cast( null as VARCHAR(255)), cast(null as int))) as ref" | grep -v "selected." | tail -n 1
148
+            fi
149
+
150
+            # disconnect from database
151
+            db2 connect reset > /dev/null
152
+        done
153
+EOF
154
+WAITMAX
155
+    return $?
156
+}
157
+
158
+if [ "$1" = "query" ]; then
159
+    query_instance $2
160
+    exit $?
161
+else
162
+    #### RUN CACHED #####
163
+    function file_age {
164
+        /usr/bin/perl -e 'if (! -f $ARGV[0]){die "0000000"};$mtime=(stat($ARGV[0]))[9];print ($^T-$mtime);' "$1"
165
+    }
166
+
167
+    if [ ! -d $MK_VARDIR/cache ]; then mkdir -p $MK_VARDIR/cache ; fi
168
+
169
+
170
+    if [ -e "$MK_VARDIR/cache/mk_db2.aix.cache" ] ; then
171
+        rm $MK_VARDIR/cache/mk_db2.aix.cache
172
+    fi
173
+    INSTANCES=$(ps -ef | grep [d]b2sysc | awk '{print $1 }')
174
+
175
+    # Output any section headers
176
+    # If no data is available there will be at least the section headers
177
+    # This happens when a database is down. In this scenario the db2_version check
178
+    # should go CRIT and the other checks go stale
179
+    echo "<<<db2_version:sep(1)>>>"
180
+    echo "<<<db2_tablespaces>>>"
181
+    echo "<<<db2_counters>>>"
182
+    echo "<<<db2_logsizes>>>"
183
+    echo "<<<db2_connections>>>"
184
+    echo "<<<db2_bp_hitratios>>>"
185
+    echo "<<<db2_sort_overflow>>>"
186
+    echo "<<<db2_backup>>>"
187
+
188
+    for INSTANCE in $INSTANCES; do
189
+        CACHEFILE="$MK_VARDIR/cache/mk_db2.aix.cache.$INSTANCE"
190
+        MAXAGE=300
191
+
192
+        # Check if the creation of the cache takes way to long and delete this file
193
+        # The process might have crashed...
194
+        # Since the processes are called with waitmax it is very unlikely that
195
+        # there are still unwanted processes soiling the system.
196
+        if [ -e "$CACHEFILE.new" ] ; then
197
+            AGE=$(file_age "$CACHEFILE.new")
198
+            if [ $AGE -ge $((MAXAGE * 10)) ] ; then
199
+                rm "$CACHEFILE.new"
200
+            fi
201
+        fi
202
+
203
+        # Check if the creation of the cache takes suspiciously long and return
204
+        # nothing if the age (access time) of $CACHEFILE.new is twice the MAXAGE
205
+        if [ -e "$CACHEFILE.new" ] ; then
206
+            AGE=$(file_age "$CACHEFILE.new")
207
+            if [ $AGE -ge $((MAXAGE * 2)) ] ; then
208
+                return
209
+            fi
210
+        fi
211
+
212
+        # Check if cache file exists and is recent enough
213
+        USE_CACHEFILE=""
214
+        if [ -s "$CACHEFILE" ] ; then
215
+            AGE=$(file_age "$CACHEFILE")
216
+            if [ $AGE -le $MAXAGE ] ; then USE_CACHEFILE=1 ; fi
217
+            # Output the file in any case, even if it is
218
+            # outdated. The new file will not yet be available
219
+            cat "$CACHEFILE"
220
+        fi
221
+
222
+        # Cache file outdated and new job not yet running? Start it
223
+        if [ -z "$USE_CACHEFILE" -a ! -e "$CACHEFILE.new" ] ; then
224
+            echo "set -o noclobber ; exec > \"$CACHEFILE.new\" || exit 1 ; ./$0 query $INSTANCE && mv \"$CACHEFILE.new\" \"$CACHEFILE\" || rm -f \"$CACHEFILE\" \"$CACHEFILE.new\"" | nohup ksh 2>/dev/null &
225
+        fi
226
+
227
+    done
228
+
229
+fi
230
+
231
+exit 0

+ 147
- 0
ansible/roles/elnappo.check_mk_agent/files/plugins/mk_db2.linux View File

@@ -0,0 +1,147 @@
1
+#!/bin/bash
2
+# +------------------------------------------------------------------+
3
+# |             ____ _               _        __  __ _  __           |
4
+# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
5
+# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
6
+# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
7
+# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
8
+# |                                                                  |
9
+# | Copyright Mathias Kettner 2018             mk@mathias-kettner.de |
10
+# +------------------------------------------------------------------+
11
+#
12
+# This file is part of Check_MK.
13
+# The official homepage is at http://mathias-kettner.de/check_mk.
14
+#
15
+# check_mk is free software;  you can redistribute it and/or modify it
16
+# under the  terms of the  GNU General Public License  as published by
17
+# the Free Software Foundation in version 2.  check_mk is  distributed
18
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
19
+# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
20
+# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
21
+# tails. You should have  received  a copy of the  GNU  General Public
22
+# License along with GNU Make; see the file  COPYING.  If  not,  write
23
+# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
24
+# Boston, MA 02110-1301 USA.
25
+
26
+# Agent plugin to monitor DB/2 databases on Linux.
27
+#
28
+# Note: The script has to be accessible and executable by the DB/2
29
+#       instance users to function properly.
30
+#
31
+# The script is called in two different modes. Without arguments it:
32
+#
33
+#    - outputs the db2_version section,
34
+#    - collects all db2 instances and databases, and
35
+#    - runs the script for each database as an instance user
36
+#
37
+# With arguments the script queries the information for each database and
38
+# outputs the corresponding sections.
39
+
40
+if [ $# -eq 0 ]; then
41
+    if type timeout >/dev/null 2>&1 ; then
42
+        function waitmax () {
43
+            timeout "$@"
44
+        }
45
+    fi
46
+
47
+    INSTANCES=$(ps -ef | grep "[d]b2sysc" | awk '{print $1 }')
48
+
49
+    for INSTANCE in $INSTANCES; do
50
+        NOW=$(perl -e "print time();")
51
+
52
+        echo ""
53
+        echo '<<<db2_version:sep(1)>>>'
54
+        DBVERSION=$(su - "${INSTANCE}" -c "db2 get snapshot for dbm" | grep -e 'Product name' -e 'Service level' | awk -v FS='=' '{print $2}' | sed 'N;s/\n/,/g' | sed 's/ //g')
55
+        echo "$INSTANCE" "$DBVERSION"
56
+        VERSION_NUMBER=$(echo "$DBVERSION" | sed  -e 's/DB2v\(.*\),.*/\1/' | awk -v FS="." '{print $1"."$2}')
57
+
58
+        DBS=$(su - "${INSTANCE}" -c "db2 list active databases" | grep 'Database name' | awk '{ print $NF }')
59
+
60
+        DB_PORT='port 0'
61
+        GET_PORT=1
62
+        for DB in $DBS; do
63
+            if [ 1 -eq $GET_PORT ] ; then
64
+                # Each database in an instance has the same port information
65
+                db2_tcp_service=$(su - "${INSTANCE}" -c "db2 -x get dbm cfg" | grep "TCP/IP Service" | awk -v FS='=' '{print $2}' | tr -d ' ')
66
+                if ( grep "$db2_tcp_service" /etc/services | grep -q "^$db2_tcp_service " ); then
67
+                    DB_PORT='port '$(grep "$db2_tcp_service" /etc/services | grep "^$db2_tcp_service " | awk '{print $2}' | awk -v FS="/" '{print $1}')
68
+                fi
69
+                GET_PORT=0
70
+            fi
71
+            SCRIPT=$(readlink -f "$0")
72
+            waitmax -s 9 10 su - "${INSTANCE}" -c "\"${SCRIPT}\" \"${INSTANCE}\" \"${DB}\" \"${VERSION_NUMBER}\" \"${NOW}\" \"${DB_PORT}\""
73
+        done
74
+    done
75
+else
76
+    INSTANCE=$1
77
+    DB=$2
78
+    VERSION_NUMBER=$3
79
+    NOW=$4
80
+    DB_PORT=$5
81
+
82
+    function compare_version_greater_equal {
83
+        GREATER_ONE=$(echo "$1 $2" | awk "{if ($1 >= $2) print $1; else print $2}")
84
+        if [ "$GREATER_ONE" == "$1" ] ; then
85
+            return 0
86
+        else
87
+            return 1
88
+        fi
89
+        return 0
90
+    }
91
+
92
+    millis_before=$(date +"%s%3N")
93
+    if db2 +o connect to "$DB"; then
94
+        millis_after=$(date +"%s%3N")
95
+        millis_diff=$(( millis_after - millis_before ))
96
+
97
+        echo "<<<db2_connections>>>"
98
+        echo "[[[$INSTANCE:$DB]]]"
99
+        echo "$DB_PORT"
100
+        echo "connections " | tr -d '\n'
101
+        db2 -x "SELECT count(*)-1 FROM TABLE(mon_get_connection(CAST(NULL AS BIGINT), -2)) AS t"
102
+        echo "latency ${millis_diff}"
103
+
104
+        echo "<<<db2_tablespaces>>>"
105
+        echo "[[[$INSTANCE:$DB]]]"
106
+        SQL="SELECT tbsp_name, tbsp_type, tbsp_state, tbsp_usable_size_kb, tbsp_total_size_kb, tbsp_used_size_kb, tbsp_free_size_kb FROM sysibmadm.tbsp_utilization WHERE tbsp_type = 'DMS' UNION ALL SELECT tu.tbsp_name, tu.tbsp_type, tu.tbsp_state, tu.tbsp_usable_size_kb, tu.tbsp_total_size_kb, tu.tbsp_used_size_kb, (cu.fs_total_size_kb - cu.fs_used_size_kb) AS tbsp_free_size_kb FROM sysibmadm.tbsp_utilization tu INNER JOIN ( SELECT tbsp_id, 1 AS fs_total_size_kb, 0 AS fs_used_size_kb FROM sysibmadm.container_utilization WHERE (fs_total_size_kb IS NULL OR fs_used_size_kb IS NULL) GROUP BY tbsp_id) cu ON (tu.tbsp_type = 'SMS' AND tu.tbsp_id = cu.tbsp_id) UNION ALL SELECT tu.tbsp_name, tu.tbsp_type, tu.tbsp_state, tu.tbsp_usable_size_kb, tu.tbsp_total_size_kb, tu.tbsp_used_size_kb, (cu.fs_total_size_kb - cu.fs_used_size_kb) AS tbsp_free_size_kb FROM sysibmadm.tbsp_utilization tu INNER JOIN ( SELECT tbsp_id, SUM(fs_total_size_kb) AS fs_total_size_kb, SUM(fs_used_size_kb) AS fs_used_size_kb FROM sysibmadm.container_utilization WHERE (fs_total_size_kb IS NOT NULL AND fs_used_size_kb IS NOT NULL) GROUP BY tbsp_id) cu ON (tu.tbsp_type = 'SMS' AND tu.tbsp_id = cu.tbsp_id)"
107
+        db2 "${SQL}" | awk '{print $1" "$2" "$3" "$4" "$5" "$6" "$7}' | sed -e '/^[ ]*$/d' -e '/^-/d' -e '/selected/d'
108
+
109
+        echo "<<<db2_counters>>>"
110
+        echo "TIMESTAMP $NOW"
111
+        echo "$INSTANCE:$DB deadlocks " | tr -d '\n'
112
+        db2 -x "SELECT deadlocks from sysibmadm.snapdb" | tr -d ' '
113
+        echo "$INSTANCE:$DB lockwaits " | tr -d '\n'
114
+        db2 -x "SELECT lock_waits from sysibmadm.snapdb" | tr -d ' '
115
+        echo "$INSTANCE:$DB sortoverflows " | tr -d '\n'
116
+        db2 -x "SELECT sort_overflows from sysibmadm.snapdb" | tr -d ' '
117
+
118
+        echo "<<<db2_logsizes>>>"
119
+        echo "TIMESTAMP $NOW"
120
+        echo "[[[$INSTANCE:$DB]]]"
121
+        echo "usedspace " | tr -d '\n'
122
+        db2 -x "SELECT total_log_used from sysibmadm.snapdb" | tr -d ' '
123
+        db2 -x "SELECT NAME, VALUE FROM SYSIBMADM.DBCFG WHERE NAME IN ('logfilsiz','logprimary','logsecond')"| awk '{print $1" "$2}'
124
+
125
+        echo "<<<db2_bp_hitratios>>>"
126
+        echo "[[[$INSTANCE:$DB]]]"
127
+        db2 "SELECT SUBSTR(BP_NAME,1,14) AS BP_NAME, TOTAL_HIT_RATIO_PERCENT, DATA_HIT_RATIO_PERCENT, INDEX_HIT_RATIO_PERCENT, XDA_HIT_RATIO_PERCENT FROM SYSIBMADM.BP_HITRATIO" | grep -v "selected." | sed -e '/^$/d' -e '/^-/d'
128
+
129
+        echo "<<<db2_sort_overflow>>>"
130
+        echo "[[[$INSTANCE:$DB]]]"
131
+        db2 -x "get snapshot for database on $DB" | grep -e "^Total sorts" -e "^Sort overflows" | tr -d '='
132
+
133
+        echo "<<<db2_backup>>>"
134
+        echo "[[[$INSTANCE:$DB]]]"
135
+        if compare_version_greater_equal "$VERSION_NUMBER" 10.5; then
136
+          # MON_GET_DATBASE(-2) gets information of all active members
137
+          db2 -x "select LAST_BACKUP from TABLE (MON_GET_DATABASE(-2))" | grep -v "selected." | tail -n 1
138
+        else
139
+          db2 -x "select SQLM_ELM_LAST_BACKUP from table(SNAPSHOT_DATABASE( cast( null as VARCHAR(255)), cast(null as int))) as ref" | grep -v "selected." | tail -n 1
140
+        fi
141
+
142
+        # disconnect from database
143
+        db2 connect reset > /dev/null
144
+    fi
145
+fi
146
+
147
+exit 0

+ 55
- 0
ansible/roles/elnappo.check_mk_agent/files/plugins/mk_docker_container_piggybacked View File

@@ -0,0 +1,55 @@
1
+#!/bin/bash
2
+# +------------------------------------------------------------------+
3
+# |             ____ _               _        __  __ _  __           |
4
+# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
5
+# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
6
+# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
7
+# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
8
+# |                                                                  |
9
+# | Copyright Mathias Kettner 2018             mk@mathias-kettner.de |
10
+# +------------------------------------------------------------------+
11
+#
12
+# This file is part of Check_MK.
13
+# The official homepage is at http://mathias-kettner.de/check_mk.
14
+#
15
+# check_mk is free software;  you can redistribute it and/or modify it
16
+# under the  terms of the  GNU General Public License  as published by
17
+# the Free Software Foundation in version 2.  check_mk is  distributed
18
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
19
+# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
20
+# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
21
+# tails. You should have  received  a copy of the  GNU  General Public
22
+# License along with GNU Make; see the file  COPYING.  If  not,  write
23
+# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
24
+# Boston, MA 02110-1301 USA.
25
+
26
+# $REMOTE is exported from check_mk_agent.linux
27
+
28
+if type docker > /dev/null 2>&1; then
29
+    NODE_NAME=$(docker info --format "{{json .Name}}")
30
+
31
+    # For the container status, we want information about *all* containers
32
+    for CONTAINER_ID in $(docker container ls -q --all); do
33
+        echo "<<<<${CONTAINER_ID}>>>>"
34
+        docker inspect "$CONTAINER_ID" \
35
+            --format='{{println "<<<docker_container_status>>>"}}{{json .State}}{{println}}{{println "<<<docker_container_node_name>>>"}}{{println '"$NODE_NAME"'}}{{println "<<<docker_container_labels>>>"}}{{json .Config.Labels}}{{println}}{{println "<<<docker_container_network>>>"}}{{json .NetworkSettings}}{{println}}'
36
+
37
+        if [ "$(docker inspect -f '{{.State.Running}}' "$CONTAINER_ID")" = "true" ]; then
38
+            # Is there a regular agent available in the container? Use it!
39
+            #
40
+            # Otherwise execute the agent of the node in the context of the container.
41
+            # Using this approach we should always get at least basic information from
42
+            # the container.
43
+            # Once it comes to plugins and custom configuration the user needs to use
44
+            # a little more complex setup. Have a look at the documentation.
45
+            AGENT_PATH=$(docker container exec "$CONTAINER_ID" bash -c "type check_mk_agent" 2>/dev/null) || AGENT_PATH=
46
+            if [ -n "$AGENT_PATH" ]; then
47
+                docker container exec --env "REMOTE=$REMOTE" "$CONTAINER_ID" check_mk_agent
48
+            elif docker container exec "$CONTAINER_ID" which bash >/dev/null 2>&1; then
49
+                docker container exec --env MK_FROM_NODE=1 --env "REMOTE=$REMOTE" -i "$CONTAINER_ID" bash < "$0"
50
+            fi
51
+        fi
52
+
53
+        echo "<<<<>>>>"
54
+    done
55
+fi

+ 33
- 0
ansible/roles/elnappo.check_mk_agent/files/plugins/mk_filehandler View File

@@ -0,0 +1,33 @@
1
+#!/bin/bash
2
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
3
+# +------------------------------------------------------------------+
4
+# |             ____ _               _        __  __ _  __           |
5
+# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
6
+# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
7
+# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
8
+# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
9
+# |                                                                  |
10
+# | Copyright Mathias Kettner 2014             mk@mathias-kettner.de |
11
+# +------------------------------------------------------------------+
12
+#
13
+# This file is part of Check_MK.
14
+# The official homepage is at http://mathias-kettner.de/check_mk.
15
+#
16
+# check_mk is free software;  you can redistribute it and/or modify it
17
+# under the  terms of the  GNU General Public License  as published by
18
+# the Free Software Foundation in version 2.  check_mk is  distributed
19
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
20
+# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
21
+# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
22
+# tails. You should have  received  a copy of the  GNU  General Public
23
+# License along with GNU Make; see the file  COPYING.  If  not,  write
24
+# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
25
+# Boston, MA 02110-1301 USA.
26
+
27
+FILE=/proc/sys/fs/file-nr
28
+
29
+echo '<<<filehandler>>>'
30
+if [ -a $FILE ]; then
31
+    cat $FILE
32
+fi
33
+

+ 5
- 0
ansible/roles/elnappo.check_mk_agent/files/plugins/mk_haproxy.freebsd View File

@@ -0,0 +1,5 @@
1
+if [ -r /var/run/haproxy.stat ]; then
2
+	echo "<<<haproxy:sep(44)>>>"
3
+	echo "show stat" | socat - UNIX-CONNECT:/var/run/haproxy.sock
4
+fi
5
+

+ 296
- 0
ansible/roles/elnappo.check_mk_agent/files/plugins/mk_informix View File

@@ -0,0 +1,296 @@
1
+#!/bin/bash
2
+# Monitor status of LUNs on HP-UX
3
+# +------------------------------------------------------------------+
4
+# |             ____ _               _        __  __ _  __           |
5
+# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
6
+# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
7
+# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
8
+# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
9
+# |                                                                  |
10
+# | Copyright Mathias Kettner 2014             mk@mathias-kettner.de |
11
+# +------------------------------------------------------------------+
12
+#
13
+# This file is part of Check_MK.
14
+# The official homepage is at http://mathias-kettner.de/check_mk.
15
+#
16
+# check_mk is free software;  you can redistribute it and/or modify it
17
+# under the  terms of the  GNU General Public License  as published by
18
+# the Free Software Foundation in version 2.  check_mk is  distributed
19
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
20
+# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
21
+# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
22
+# tails. You should have  received  a copy of the  GNU  General Public
23
+# License along with GNU Make; see the file  COPYING.  If  not,  write
24
+# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
25
+# Boston, MA 02110-1301 USA.
26
+
27
+# Make ENV-VARs avail for subshells
28
+set -a
29
+
30
+#   .--helper--------------------------------------------------------------.
31
+#   |                    _          _                                      |
32
+#   |                   | |__   ___| |_ __   ___ _ __                      |
33
+#   |                   | '_ \ / _ \ | '_ \ / _ \ '__|                     |
34
+#   |                   | | | |  __/ | |_) |  __/ |                        |
35
+#   |                   |_| |_|\___|_| .__/ \___|_|                        |
36
+#   |                                |_|                                   |
37
+#   '----------------------------------------------------------------------'
38
+
39
+
40
+function do_check () {
41
+    # $1:section, $2:excludelist
42
+    if echo "$2" | grep -qe "${1}"; then
43
+        return 1
44
+    else
45
+        return 0
46
+    fi
47
+}
48
+
49
+
50
+function sql () {
51
+    db="sysmaster"
52
+    sqltxt="$1"
53
+    dbaccess_par=
54
+    export DBDELIMITER="|"
55
+    echo "$sqltxt" | dbaccess ${db}
56
+}
57
+
58
+
59
+function set_excludes () {
60
+    excludes=""
61
+    if [ "$EXCLUDES" = "ALL" ]; then
62
+        excludes="$all_sections"
63
+        global_exclude=true
64
+    elif [ ! -z "$EXCLUDES" ]; then
65
+        excludes=$EXCLUDES
66
+        global_exclude=true
67
+    else
68
+        global_exclude=false
69
+    fi
70
+
71
+    if [ "$global_exclude" = "false" ]; then
72
+        excludes_i="EXCLUDES_${1}"
73
+        if [ "${!excludes_i}" = "ALL" ]; then
74
+            excludes="$all_sections"
75
+        elif [ ! -z "${!excludes_i}" ]; then
76
+            excludes=${!excludes_i}
77
+        fi
78
+    fi
79
+}
80
+
81
+
82
+#.
83
+#   .--sqls----------------------------------------------------------------.
84
+#   |                                     _                                |
85
+#   |                           ___  __ _| |___                            |
86
+#   |                          / __|/ _` | / __|                           |
87
+#   |                          \__ \ (_| | \__ \                           |
88
+#   |                          |___/\__, |_|___/                           |
89
+#   |                                  |_|                                 |
90
+#   '----------------------------------------------------------------------'
91
+
92
+
93
+all_sections="sessions locks tabextents dbspaces logusage"
94
+
95
+
96
+function informix_status(){
97
+    echo "<<<informix_status:sep(58)>>>"
98
+    echo "[[[$INFORMIXSERVER/$SERVERNUM]]]"
99
+    $INFORMIXDIR/bin/onstat - >/dev/null 2>&1
100
+    state=$?
101
+    echo "Status:"$state
102
+    $INFORMIXDIR/bin/onstat -g dis
103
+    port=$(grep $INFORMIXSERVER /etc/services)
104
+    echo "PORT:"$port
105
+}
106
+
107
+
108
+function informix_sessions(){
109
+    echo "<<<informix_sessions>>>"
110
+    echo "[[[$INFORMIXSERVER/$SERVERNUM]]]"
111
+    # don't count our own session
112
+    sql "select 'SESSIONS', (count(*)-1)::int from syssessions"
113
+}
114
+
115
+
116
+function informix_locks(){
117
+    echo "<<<informix_locks>>>"
118
+    echo "[[[$INFORMIXSERVER/$SERVERNUM]]]"
119
+    # don't count our own session
120
+    sql "select 'LOCKS', (count(*)-1)::int, type from syslocks group by type"
121
+}
122
+
123
+
124
+function informix_tabextents(){
125
+    echo "<<<informix_tabextents>>>"
126
+    echo "[[[$INFORMIXSERVER/$SERVERNUM]]]"
127
+    sql "select first 10
128
+            'TABEXTENTS',
129
+            trim(n.dbsname) db,
130
+            trim(n.tabname) tab,
131
+            h.nextns extents,
132
+            nrows
133
+        from sysptnhdr h, systabnames n
134
+        where h.partnum = n.partnum
135
+        and nrows > 0
136
+        and n.dbsname not in ( 'sysadmin', 'sysuser', 'sysutils', 'sysmaster' )
137
+        and n.tabname not like 'sys%'
138
+        order by extents desc"
139
+}
140
+
141
+
142
+function informix_dbspaces(){
143
+    echo "<<<informix_dbspaces>>>"
144
+    echo "[[[$INFORMIXSERVER/$SERVERNUM]]]"
145
+    sql "select
146
+            trim(sd.name) || ' DBSPACE',
147
+            sd.dbsnum,
148
+            sd.is_temp,
149
+            sd.flags,
150
+            'CHUNK',
151
+            sc.fname,
152
+            sc.pagesize,
153
+            sc.chksize,
154
+            sc.nfree,
155
+            sc.flags,
156
+            trim(sc.mfname),
157
+            sc.mflags
158
+        from sysdbspaces sd, syschunks sc
159
+        where sd.dbsnum = sc.dbsnum
160
+        -- NO SBSPACE CURRENTLY
161
+        and sd.is_sbspace = 0
162
+        order by sd.name"
163
+}
164
+
165
+
166
+function informix_logusage(){
167
+    echo "<<<informix_logusage>>>"
168
+    echo "[[[$INFORMIXSERVER/$SERVERNUM]]]"
169
+    sql "select 'LOGUSAGE',
170
+            number,
171
+            sh_pagesize,
172
+            size,
173
+            used,
174
+            flags,
175
+            'is_used:'||is_used,
176
+            'is_current:'||is_current,
177
+            'is_backed_up:'||is_backed_up,
178
+            'is_new:'||is_new,
179
+            'is_archived:'||is_archived,
180
+            'is_temp:'||is_temp,
181
+            'is_pre_dropped:'||is_pre_dropped
182
+        from syslogs, sysshmvals
183
+        order by number"
184
+}
185
+
186
+
187
+#.
188
+#   .--config--------------------------------------------------------------.
189
+#   |                                      __ _                            |
190
+#   |                      ___ ___  _ __  / _(_) __ _                      |
191
+#   |                     / __/ _ \| '_ \| |_| |/ _` |                     |
192
+#   |                    | (_| (_) | | | |  _| | (_| |                     |
193
+#   |                     \___\___/|_| |_|_| |_|\__, |                     |
194
+#   |                                           |___/                      |
195
+#   '----------------------------------------------------------------------'
196
+
197
+
198
+# Config opts:
199
+# - oninit-path; Default is empty, which means autodetection:
200
+#       ONINIT_PATH=<path to oninit-binary>
201
+# - Excluding sections ("status sessions locks tabextents dbspaces logusage"):
202
+#       EXCLUDES_INFORMIX_INSTANCE="SECTION SECTION ..."
203
+#       EXCLUDES_INFORMIX_INSTANCE=ALL
204
+#       EXCLUDES="SECTION SECTION ..."
205
+#       EXCLUDES=ALL
206
+
207
+
208
+if [ -f "$MK_CONFDIR/informix.cfg" ]; then
209
+    . $MK_CONFDIR/informix.cfg
210
+fi
211
+
212
+
213
+if [ -z "$ONINIT_PATH" -o ! -x "$ONINIT_PATH" ]; then
214
+    ONINIT=$(UNIX95=true ps ax  | grep oninit | grep -v grep | head -1 | awk '{print $1 " " $5}')
215
+    if [ -z "$ONINIT" ]; then
216
+        exit 0
217
+    fi
218
+
219
+    ONINIT_PATH=${ONINIT#* }
220
+    ONINIT_PID=${ONINIT% *}
221
+    case "$ONINIT_PATH" in
222
+    /*)
223
+        ;;
224
+    *)    # BUG not platform independent!
225
+        ONINIT_PATH=$(ls -l /proc/$ONINIT_PID/exe 2>/dev/null| sed 's/.* //')
226
+        ;;
227
+    esac
228
+
229
+    # If not set in config or not found we end up here
230
+    if [ -z "$ONINIT_PATH" -o ! -f "$ONINIT_PATH" ]; then
231
+        exit 1
232
+    fi
233
+fi
234
+
235
+
236
+#.
237
+#   .--main----------------------------------------------------------------.
238
+#   |                                       _                              |
239
+#   |                       _ __ ___   __ _(_)_ __                         |
240
+#   |                      | '_ ` _ \ / _` | | '_ \                        |
241
+#   |                      | | | | | | (_| | | | | |                       |
242
+#   |                      |_| |_| |_|\__,_|_|_| |_|                       |
243
+#   |                                                                      |
244
+#   '----------------------------------------------------------------------'
245
+
246
+
247
+for IDSENV in $( export INFORMIXDIR=${ONINIT_PATH%/bin*}
248
+    $INFORMIXDIR/bin/onstat -g dis | \
249
+        egrep '^Server[         ]*:|^Server Number[     ]*:|^INFORMIX|^SQLHOSTS|^ONCONFIG' | \
250
+        sed -e 's/Server Number/SERVERNUM/' \
251
+            -e 's/Server/INFORMIXSERVER/' \
252
+            -e 's/SQLHOSTS/INFORMIXSQLHOSTS/' \
253
+            -e 's/[     ]*:[    ]*/=/' | \
254
+         tr '\n' ';' | \
255
+        sed -e 's/;$/\n/' -e 's/;\(INFORMIXSERVER=[^;]*;\)/\n\1/g'
256
+
257
+    ) ; do
258
+    (
259
+        # Set environment
260
+        eval $IDSENV
261
+    	PATH=$INFORMIXDIR/bin:$PATH
262
+
263
+	    # try to set them via 'onstat -g env' otherwise
264
+	    # DB HAS TO BE RUNNING
265
+	    if [ -z "$INFORMIXSQLHOSTS" -o -z "$ONCONFIG" ]; then
266
+	        onstat -g env | egrep -e '^INFORMIXSQLHOSTS' \
267
+	    	                      -e '^ONCONFIG' |       \
268
+	    	                sed   -e 's/[         ][      ]*/=/'
269
+	    fi
270
+
271
+        informix_status
272
+
273
+        set_excludes $INFORMIXSERVER
274
+
275
+        if do_check "sessions" "$excludes"; then
276
+            informix_sessions
277
+        fi
278
+
279
+        if do_check "locks" "$excludes"; then
280
+            informix_locks
281
+        fi
282
+
283
+        if do_check "tabextents" "$excludes"; then
284
+            informix_tabextents
285
+        fi
286
+
287
+        if do_check "dbspaces" "$excludes"; then
288
+            informix_dbspaces
289
+        fi
290
+
291
+        if do_check "logusage" "$excludes"; then
292
+            informix_logusage
293
+        fi
294
+    )
295
+done
296
+

+ 357
- 0
ansible/roles/elnappo.check_mk_agent/files/plugins/mk_inotify View File

@@ -0,0 +1,357 @@
1
+#!/usr/bin/python
2
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
3
+# +------------------------------------------------------------------+
4
+# |             ____ _               _        __  __ _  __           |
5
+# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
6
+# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
7
+# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
8
+# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
9
+# |                                                                  |
10
+# | Copyright Mathias Kettner 2016             mk@mathias-kettner.de |
11
+# +------------------------------------------------------------------+
12
+#
13
+# This file is part of Check_MK.
14
+# The official homepage is at http://mathias-kettner.de/check_mk.
15
+#
16
+# check_mk is free software;  you can redistribute it and/or modify it
17
+# under the  terms of the  GNU General Public License  as published by
18
+# the Free Software Foundation in version 2.  check_mk is  distributed
19
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
20
+# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
21
+# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
22
+# tails. You should have  received  a copy of the  GNU  General Public
23
+# License along with GNU Make; see the file  COPYING.  If  not,  write
24
+# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
25
+# Boston, MA 02110-1301 USA.
26
+
27
+import os
28
+import sys
29
+import time
30
+import signal
31
+import ConfigParser
32
+
33
+try:
34
+    # TODO: We should probably ship this package.
35
+    import pyinotify  # pylint: disable=import-error
36
+except:
37
+    sys.stderr.write("Error: Python plugin pyinotify is not installed")
38
+    sys.exit(1)
39
+
40
+def usage():
41
+    sys.stdout.write("Usage: mk_inotify [-g]\n")
42
+    sys.stdout.write("         -g: run in foreground\n\n")
43
+
44
+# Available options:
45
+# -g: run in foreground
46
+opt_foreground = False
47
+if len(sys.argv) == 2 and sys.argv[1] == "-g":
48
+    opt_foreground = True
49
+
50
+mk_confdir = os.getenv("MK_CONFDIR") or "/etc/check_mk"
51
+mk_vardir = os.getenv("MK_VARDIR")   or "/var/lib/check_mk_agent"
52
+
53
+config_filename  = mk_confdir + "/mk_inotify.cfg"
54
+configured_paths = mk_vardir  + "/mk_inotify.configured"
55
+pid_filename     = mk_vardir  + "/mk_inotify.pid"
56
+
57
+
58
+config = ConfigParser.SafeConfigParser({})
59
+if not os.path.exists(config_filename):
60
+    sys.exit(0)
61
+config_mtime = os.stat(config_filename).st_mtime
62
+config.read(config_filename)
63
+
64
+# Configurable in Agent Bakery
65
+heartbeat_timeout         = config.getint("global", "heartbeat_timeout")
66
+write_interval            = config.getint("global", "write_interval")
67
+max_messages_per_interval = config.getint("global", "max_messages_per_interval")
68
+stats_retention           = config.getint("global", "stats_retention")
69
+config.remove_section("global")
70
+
71
+def output_data():
72
+    sys.stdout.write("<<<inotify:sep(9)>>>\n")
73
+    if os.path.exists(configured_paths):
74
+        sys.stdout.write(file(configured_paths).read())
75
+
76
+    now = time.time()
77
+    for dirpath, _unused_dirnames, filenames in os.walk(mk_vardir):
78
+        for filename in filenames:
79
+            if filename.startswith("mk_inotify.stats"):
80
+                try:
81
+                    the_file = "%s/%s" % (dirpath, filename)
82
+                    filetime = os.stat(the_file).st_mtime
83
+                    file_age = now - filetime
84
+                    if file_age > 5:
85
+                        sys.stdout.write(file(the_file).read())
86
+                    if file_age > stats_retention:
87
+                        os.unlink(the_file)
88
+                except:
89
+                    pass
90
+        break
91
+
92
+# Check if another mk_inotify process is already running
93
+if os.path.exists(pid_filename):
94
+    pid = file(pid_filename).read()
95
+    proc_cmdline = "/proc/%s/cmdline" % pid
96
+    if os.path.exists(proc_cmdline):
97
+        cmdline = file(proc_cmdline).read()
98
+        cmdline_tokens = cmdline.split("\0")
99
+        if "mk_inotify" in cmdline_tokens[1]:
100
+            # Another mk_notify process is already running..
101
+            # Simply output the current statistics and exit
102
+            output_data()
103
+
104
+            # The pidfile is also the heartbeat file for the running process
105
+            os.utime(pid_filename, None)
106
+            sys.exit(0)
107
+
108
+
109
+#   .--Fork----------------------------------------------------------------.
110
+#   |                         _____          _                             |
111
+#   |                        |  ___|__  _ __| | __                         |
112
+#   |                        | |_ / _ \| '__| |/ /                         |
113
+#   |                        |  _| (_) | |  |   <                          |
114
+#   |                        |_|  \___/|_|  |_|\_\                         |
115
+#   |                                                                      |
116
+#   +----------------------------------------------------------------------+
117
+#   Reaching this point means that no mk_inotify is currently running
118
+
119
+if not opt_foreground:
120
+    try:
121
+        pid = os.fork()
122
+        if pid > 0:
123
+            sys.exit(0)
124
+        # Decouple from parent environment
125
+        os.chdir("/")
126
+        os.umask(0)
127
+        os.setsid()
128
+
129
+        # Close all fd
130
+        for fd in range(0, 256):
131
+            try:
132
+                os.close(fd)
133
+            except OSError:
134
+                pass
135
+    except Exception, e:
136
+        sys.stderr.write("Error forking mk_inotify: %s" % e)
137
+
138
+    # Save pid of working process.
139
+    file(pid_filename, "w").write("%d" % os.getpid())
140
+#.
141
+#   .--Main----------------------------------------------------------------.
142
+#   |                        __  __       _                                |
143
+#   |                       |  \/  | __ _(_)_ __                           |
144
+#   |                       | |\/| |/ _` | | '_ \                          |
145
+#   |                       | |  | | (_| | | | | |                         |
146
+#   |                       |_|  |_|\__,_|_|_| |_|                         |
147
+#   |                                                                      |
148
+#   +----------------------------------------------------------------------+
149
+
150
+folder_configs = {} # Computed configuration
151
+output = []         # Data to be written to disk
152
+def get_watched_files():
153
+    files = set([])
154
+    for folder, attributes in folder_configs.items():
155
+        for filenames in attributes["monitor_files"].values():
156
+            for filename in filenames:
157
+                files.add("configured\tfile\t%s/%s" % (folder, filename))
158
+        if attributes.get("monitor_all"):
159
+            files.add("configured\tfolder\t%s" % (folder))
160
+    return files
161
+
162
+def wakeup_handler(signum, frame):
163
+    global output
164
+    if output:
165
+        if opt_foreground:
166
+            sys.stdout.write("%s\n" % "\n".join(output))
167
+            sys.stdout.write("%s\n" % "\n".join(get_watched_files()))
168
+        else:
169
+            filename = "mk_inotify.stats.%d" % time.time()
170
+            file("%s/%s" % (mk_vardir, filename), "w").write("\n".join(output)+"\n")
171
+        output = []
172
+
173
+    # Check if configuration has changed -> restart
174
+    if (config_mtime != os.stat(config_filename).st_mtime):
175
+        os.execv(__file__, sys.argv)
176
+
177
+    # Exit on various instances
178
+    if not opt_foreground:
179
+        if not os.path.exists(pid_filename): # pidfile is missing
180
+            sys.exit(0)
181
+        if time.time() - os.stat(pid_filename).st_mtime > heartbeat_timeout: # heartbeat timeout
182
+            sys.exit(0)
183
+        if os.getpid() != int(file(pid_filename).read()): # pidfile differs
184
+            sys.exit(0)
185
+
186
+    update_watched_folders()
187
+    signal.alarm(write_interval)
188
+
189
+def do_output(what, event):
190
+    if event.dir:
191
+        return # Only monitor files
192
+
193
+    if len(output) > max_messages_per_interval:
194
+        last_message = "warning\tMaximum messages reached: %d per %d seconds" % \
195
+                    (max_messages_per_interval, write_interval)
196
+        if output[-1] != last_message:
197
+            output.append(last_message)
198
+        return
199
+
200
+    path        = event.path
201
+    path_config = folder_configs.get(path)
202
+    if not path_config:
203
+        return # shouldn't happen, maybe on subfolders (not supported)
204
+
205
+    filename = os.path.basename(event.pathname)
206
+    if what in path_config["monitor_all"] or\
207
+       filename in path_config["monitor_files"].get(what, []):
208
+        line = "%d\t%s\t%s" % (time.time(), what, event.pathname)
209
+        if map_events[what][1]: # Check if filestats are enabled
210
+            try:
211
+                stats = os.stat(event.pathname)
212
+                line += "\t%d\t%d" % (stats.st_size, stats.st_mtime)
213
+            except Exception:
214
+                pass
215
+        output.append(line)
216
+        if opt_foreground:
217
+            sys.stdout.write("%s\n" % line)
218
+
219
+
220
+map_events = {
221
+    # Mode     Mask                        Report_filestats (currently unused)
222
+    "access"   : (pyinotify.IN_ACCESS,     False), # pylint: disable=no-member
223
+    "open"     : (pyinotify.IN_OPEN,       False), # pylint: disable=no-member
224
+    "create"   : (pyinotify.IN_CREATE,     False), # pylint: disable=no-member
225
+    "delete"   : (pyinotify.IN_DELETE,     False), # pylint: disable=no-member
226
+    "modify"   : (pyinotify.IN_MODIFY,     False), # pylint: disable=no-member
227
+    "movedto"  : (pyinotify.IN_MOVED_TO,   False), # pylint: disable=no-member
228
+    "movedfrom": (pyinotify.IN_MOVED_FROM, False), # pylint: disable=no-member
229
+    "moveself" : (pyinotify.IN_MOVE_SELF,  False), # pylint: disable=no-member
230
+}
231
+
232
+class NotifyEventHandler(pyinotify.ProcessEvent):
233
+    def process_IN_MOVED_TO(self, event):
234
+        do_output("movedto", event)
235
+
236
+    def process_IN_MOVED_FROM(self, event):
237
+        do_output("movedfrom", event)
238
+
239
+    def process_IN_MOVE_SELF(self, event):
240
+        do_output("moveself", event)
241
+#    def process_IN_CLOSE_NOWRITE(self, event):
242
+#        print "CLOSE_NOWRITE event:", event.pathname
243
+#
244
+#    def process_IN_CLOSE_WRITE(self, event):
245
+#        print "CLOSE_WRITE event:", event.pathname
246
+
247
+    def process_IN_CREATE(self, event):
248
+        do_output("create", event)
249
+
250
+    def process_IN_DELETE(self, event):
251
+        do_output("delete", event)
252
+
253
+    def process_IN_MODIFY(self, event):
254
+        do_output("modify", event)
255
+
256
+    def process_IN_OPEN(self, event):
257
+        do_output("open", event)
258
+
259
+
260
+# Watch manager
261
+wm = pyinotify.WatchManager()
262
+def update_watched_folders():
263
+    for folder, attributes in folder_configs.items():
264
+        if attributes.get("watch_descriptor"):
265
+            if not wm.get_path(attributes["watch_descriptor"].get(folder)):
266
+                del attributes["watch_descriptor"]
267
+        else:
268
+            if os.path.exists(folder):
269
+                new_wd = wm.add_watch(folder, attributes["mask"], rec=True)
270
+                if new_wd.get(folder) > 0:
271
+                    attributes["watch_descriptor"] = new_wd
272
+
273
+
274
+def main():
275
+    # Read config
276
+
277
+    for section in config.sections():
278
+        section_tokens = section.split("|")
279
+
280
+        folder = section_tokens[0]
281
+        folder_configs.setdefault(folder, {"add_modes": {},
282
+                                           "del_modes": {},
283
+                                           "all_add_modes": set([]),
284
+                                           "all_del_modes": set([])})
285
+
286
+        files = None
287
+        if len(section_tokens) > 1:
288
+            files = set(section_tokens[1:])
289
+
290
+        add_modes = set([])
291
+        del_modes = set([])
292
+        for key, value in config.items(section):
293
+            if key in map_events:
294
+                if value == "1":
295
+                    add_modes.add(key)
296
+                else:
297
+                    del_modes.add(key)
298
+
299
+        if files:
300
+            for mode in add_modes:
301
+                folder_configs[folder]["add_modes"].setdefault(mode, set([]))
302
+                folder_configs[folder]["add_modes"][mode].update(files)
303
+            for mode in del_modes:
304
+                folder_configs[folder]["del_modes"].setdefault(mode, set([]))
305
+                folder_configs[folder]["del_modes"][mode].update(files)
306
+        else:
307
+            folder_configs[folder]["all_add_modes"].update(add_modes)
308
+            folder_configs[folder]["all_del_modes"].update(del_modes)
309
+
310
+
311
+    # Evaluate config
312
+    for folder, attributes in folder_configs.items():
313
+        required_modes = set([])
314
+        for mode in attributes["add_modes"].keys():
315
+            if mode not in attributes["all_del_modes"]:
316
+                required_modes.add(mode)
317
+
318
+        files_to_monitor = {}
319
+        skip_modes = set([])
320
+        for mode in required_modes:
321
+            files_to_monitor.setdefault(mode, set([]))
322
+            files_to_monitor[mode].update(attributes["add_modes"][mode])
323
+            files_to_monitor[mode] -= attributes["del_modes"].get(mode, set([]))
324
+            if not files_to_monitor[mode]:
325
+                skip_modes.add(mode)
326
+
327
+        attributes["monitor_files"] = files_to_monitor
328
+        attributes["monitor_all"]   = attributes["all_add_modes"] - attributes["all_del_modes"]
329
+        attributes["modes"]         = required_modes - skip_modes
330
+
331
+        # Determine mask
332
+        attributes["mask"] = 0
333
+        for mode in attributes["modes"]:
334
+            attributes["mask"] |= map_events[mode][0]
335
+        for mode in attributes["monitor_all"]:
336
+            attributes["mask"] |= map_events[mode][0]
337
+
338
+    update_watched_folders()
339
+    if opt_foreground:
340
+        import pprint
341
+        sys.stdout.write(pprint.pformat(folder_configs))
342
+
343
+    # Save monitored file/folder information specified in mk_inotify.cfg
344
+    file(configured_paths, "w").write("\n".join(get_watched_files())+"\n")
345
+
346
+    # Event handler
347
+    eh = NotifyEventHandler()
348
+    notifier = pyinotify.Notifier(wm, eh)
349
+
350
+    # Wake up every few seconds, check heartbeat and write data to disk
351
+    signal.signal(signal.SIGALRM, wakeup_handler)
352
+    signal.alarm(write_interval)
353
+
354
+    notifier.loop()
355
+
356
+if __name__ == '__main__':
357
+    main()

+ 69
- 0
ansible/roles/elnappo.check_mk_agent/files/plugins/mk_inventory.aix View File

@@ -0,0 +1,69 @@
1
+#!/bin/bash
2
+# +------------------------------------------------------------------+
3
+# |             ____ _               _        __  __ _  __           |
4
+# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
5
+# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
6
+# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
7
+# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
8
+# |                                                                  |
9
+# | Copyright Mathias Kettner 2014             mk@mathias-kettner.de |
10
+# +------------------------------------------------------------------+
11
+#
12
+# This file is part of Check_MK.
13
+# The official homepage is at http://mathias-kettner.de/check_mk.
14
+#
15
+# check_mk is free software;  you can redistribute it and/or modify it
16
+# under the  terms of the  GNU General Public License  as published by
17
+# the Free Software Foundation in version 2.  check_mk is  distributed
18
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
19
+# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
20
+# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
21
+# tails. You should have  received  a copy of the  GNU  General Public
22
+# License along with GNU Make; see the file  COPYING.  If  not,  write
23
+# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
24
+# Boston, MA 02110-1301 USA.
25
+
26
+# Run and *send* only once every 4 hours
27
+INTERVAL=14400
28
+
29
+FLAGFILE=$MK_VARDIR/mk_inventory.last.$REMOTE
30
+NOW=$(date +%s)
31
+UNTIL=$((NOW + INTERVAL + 600))
32
+
33
+#check if flagfile exits
34
+if [ -e "$FLAGFILE" ]; then
35
+    LAST_RUN=$(cat $FLAGFILE)
36
+else
37
+    #First run of the script
38
+    LAST_RUN=0
39
+fi
40
+
41
+if [ $(( NOW - LAST_RUN )) -ge $INTERVAL ]
42
+then
43
+    echo $NOW > $FLAGFILE
44
+
45
+    # List of installed AIX packages
46
+    if type lslpp >/dev/null; then
47
+        echo "<<<aix_packages:sep(58):persist($UNTIL)>>>"
48
+        lslpp -c -L
49
+    fi
50