@cryptotaxi247 / netdata-1 / commits / c23aed3a8

openldap monitoring plugin added (#4513)

* openldap monitoring plugin added * fixed identation, added makefile link * removed trailing whitespaces * style fixes * removed some more trailnf spaces * refactored conn method, formatting suggestions, simpler config * format suggestions, added connect-reconnect methods and alive flag * removed trailing whitespaces * trailing spaces * connection manipulation and cosmetics * charts names units and titles * added connection timeout * timout option moved * removed disable by default * timeout default value * default vars and cofig comments added * user pass commented and enabled plugin by default * python.d disabled openldap * error handling, allow anonymous bind * ldap exception * anonymous bind refactoring * none as default removed from username password

Manolis Kartsonakis committed Nov 15, 2018 at 08:17 UTC c23aed3a8edfa33015f4b86d35038f5aa79219a5
6 files changed +351 -1
collectors/python.d.plugin/Makefile.am
+1
@@ -78,6 +78,7 @@ include nvidia_smi/Makefile.inc
78 include nsd/Makefile.inc
79 include ntpd/Makefile.inc
80 include ovpn_status_log/Makefile.inc
81 +include openldap/Makefile.inc
82 include phpfpm/Makefile.inc
83 include portcheck/Makefile.inc
84 include postfix/Makefile.inc
collectors/python.d.plugin/openldap/Makefile.inc new
+13
@@ -0,0 +1,13 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +# THIS IS NOT A COMPLETE Makefile
4 +# IT IS INCLUDED BY ITS PARENT'S Makefile.am
5 +# IT IS REQUIRED TO REFERENCE ALL FILES RELATIVE TO THE PARENT
6 +
7 +# install these files
8 +dist_python_DATA += openldap/openldap.chart.py
9 +dist_pythonconfig_DATA += openldap/openldap.conf
10 +
11 +# do not install these files, but include them in the distribution
12 +dist_noinst_DATA += openldap/README.md openldap/Makefile.inc
13 +
collectors/python.d.plugin/openldap/README.md new
+57
@@ -0,0 +1,57 @@
1 +# openldap
2 +
3 +This module provides statistics information from openldap (slapd) server.
4 +Statistics are taken from LDAP monitoring interface. Manual page, slapd-monitor(5) is available.
5 +
6 +**Requirement:**
7 +* Follow instructions from https://www.openldap.org/doc/admin24/monitoringslapd.html to activate monitoring interface.
8 +* Install python ldap module `pip install ldap` or `yum install python-ldap`
9 +* Modify openldap.conf with your credentials
10 +
11 +### Module gives information with following charts:
12 +
13 +1. **connections**
14 + * total connections number
15 +
16 +2. **Bytes**
17 + * sent
18 +
19 +3. **operations**
20 + * completed
21 + * initiated
22 +
23 +4. **referrals**
24 + * sent
25 +
26 +5. **entries**
27 + * sent
28 +
29 +6. **ldap operations**
30 + * bind
31 + * search
32 + * unbind
33 + * add
34 + * delete
35 + * modify
36 + * compare
37 +
38 +7. **waiters**
39 + * read
40 + * write
41 +
42 +
43 +
44 +### configuration
45 +
46 +Sample:
47 +
48 +```yaml
49 +openldap:
50 + name : 'local'
51 + username : "cn=monitor,dc=superb,dc=eu"
52 + password : "testpass"
53 + server : 'localhost'
54 + port : 389
55 +```
56 +
57 +---
collectors/python.d.plugin/openldap/openldap.chart.py new
+204
@@ -0,0 +1,204 @@
1 +# -*- coding: utf-8 -*-
2 +# Description: openldap netdata python.d module
3 +# Author: Manolis Kartsonakis (ekartsonakis)
4 +# SPDX-License-Identifier: GPL-3.0+
5 +
6 +try:
7 + import ldap
8 + HAS_LDAP = True
9 +except ImportError:
10 + HAS_LDAP = False
11 +
12 +from bases.FrameworkServices.SimpleService import SimpleService
13 +
14 +# default module values (can be overridden per job in `config`)
15 +priority = 60000
16 +
17 +DEFAULT_SERVER = 'localhost'
18 +DEFAULT_PORT = '389'
19 +DEFAULT_TIMEOUT = 1
20 +
21 +ORDER = [
22 + 'total_connections',
23 + 'bytes_sent',
24 + 'operations',
25 + 'referrals_sent',
26 + 'entries_sent',
27 + 'ldap_operations',
28 + 'waiters'
29 +]
30 +
31 +CHARTS = {
32 + 'total_connections': {
33 + 'options': [None, 'Total Connections', 'connections/s', 'ldap', 'openldap.total_connections', 'line'],
34 + 'lines': [
35 + ['total_connections', 'connections', 'incremental']
36 + ]
37 + },
38 + 'bytes_sent': {
39 + 'options': [None, 'Traffic', 'KB/s', 'ldap', 'openldap.traffic_stats', 'line'],
40 + 'lines': [
41 + ['bytes_sent', 'sent', 'incremental', 1, 1024]
42 + ]
43 + },
44 + 'operations': {
45 + 'options': [None, 'Operations Status', 'ops/s', 'ldap', 'openldap.operations_status', 'line'],
46 + 'lines': [
47 + ['completed_operations', 'completed', 'incremental'],
48 + ['initiated_operations', 'initiated', 'incremental']
49 + ]
50 + },
51 + 'referrals_sent': {
52 + 'options': [None, 'Referrals', 'referals/s', 'ldap', 'openldap.referrals', 'line'],
53 + 'lines': [
54 + ['referrals_sent', 'sent', 'incremental']
55 + ]
56 + },
57 + 'entries_sent': {
58 + 'options': [None, 'Entries', 'entries/s', 'ldap', 'openldap.entries', 'line'],
59 + 'lines': [
60 + ['entries_sent', 'sent', 'incremental']
61 + ]
62 + },
63 + 'ldap_operations': {
64 + 'options': [None, 'Operations', 'ops/s', 'ldap', 'openldap.ldap_operations', 'line'],
65 + 'lines': [
66 + ['bind_operations', 'bind', 'incremental'],
67 + ['search_operations', 'search', 'incremental'],
68 + ['unbind_operations', 'unbind', 'incremental'],
69 + ['add_operations', 'add', 'incremental'],
70 + ['delete_operations', 'delete', 'incremental'],
71 + ['modify_operations', 'modify', 'incremental'],
72 + ['compare_operations', 'compare', 'incremental']
73 + ]
74 + },
75 + 'waiters': {
76 + 'options': [None, 'Waiters', 'waiters/s', 'ldap', 'openldap.waiters', 'line'],
77 + 'lines': [
78 + ['write_waiters', 'write', 'incremental'],
79 + ['read_waiters', 'read', 'incremental']
80 + ]
81 + },
82 +}
83 +
84 +# Stuff to gather - make tuples of DN dn and attrib to get
85 +SEARCH_LIST = {
86 + 'total_connections': (
87 + 'cn=Total,cn=Connections,cn=Monitor', 'monitorCounter',
88 + ),
89 + 'bytes_sent': (
90 + 'cn=Bytes,cn=Statistics,cn=Monitor', 'monitorCounter',
91 + ),
92 + 'completed_operations': (
93 + 'cn=Operations,cn=Monitor', 'monitorOpCompleted',
94 + ),
95 + 'initiated_operations': (
96 + 'cn=Operations,cn=Monitor', 'monitorOpInitiated',
97 + ),
98 + 'referrals_sent': (
99 + 'cn=Referrals,cn=Statistics,cn=Monitor', 'monitorCounter',
100 + ),
101 + 'entries_sent': (
102 + 'cn=Entries,cn=Statistics,cn=Monitor', 'monitorCounter',
103 + ),
104 + 'bind_operations': (
105 + 'cn=Bind,cn=Operations,cn=Monitor', 'monitorOpCompleted',
106 + ),
107 + 'unbind_operations': (
108 + 'cn=Unbind,cn=Operations,cn=Monitor', 'monitorOpCompleted',
109 + ),
110 + 'add_operations': (
111 + 'cn=Add,cn=Operations,cn=Monitor', 'monitorOpInitiated',
112 + ),
113 + 'delete_operations': (
114 + 'cn=Delete,cn=Operations,cn=Monitor', 'monitorOpCompleted',
115 + ),
116 + 'modify_operations': (
117 + 'cn=Modify,cn=Operations,cn=Monitor', 'monitorOpCompleted',
118 + ),
119 + 'compare_operations': (
120 + 'cn=Compare,cn=Operations,cn=Monitor', 'monitorOpCompleted',
121 + ),
122 + 'search_operations': (
123 + 'cn=Search,cn=Operations,cn=Monitor', 'monitorOpCompleted',
124 + ),
125 + 'write_waiters': (
126 + 'cn=Write,cn=Waiters,cn=Monitor', 'monitorCounter',
127 + ),
128 + 'read_waiters': (
129 + 'cn=Read,cn=Waiters,cn=Monitor', 'monitorCounter',
130 + ),
131 +}
132 +
133 +
134 +class Service(SimpleService):
135 + def __init__(self, configuration=None, name=None):
136 + SimpleService.__init__(self, configuration=configuration, name=name)
137 + self.order = ORDER
138 + self.definitions = CHARTS
139 +
140 + self.server = configuration.get('server', DEFAULT_SERVER)
141 + self.port = configuration.get('port', DEFAULT_PORT)
142 + self.username = configuration.get('username')
143 + self.password = configuration.get('password')
144 + self.timeout = configuration.get('timeout', DEFAULT_TIMEOUT)
145 +
146 + self.alive = False
147 + self.conn = None
148 +
149 + def disconnect(self):
150 + if self.conn:
151 + self.conn.unbind()
152 + self.conn = None
153 + self.alive = False
154 +
155 + def connect(self):
156 + try:
157 + self.conn = ldap.initialize('ldap://%s:%s' % (self.server, self.port))
158 + self.conn.set_option(ldap.OPT_NETWORK_TIMEOUT, self.timeout)
159 + if self.username and self.password:
160 + self.conn.simple_bind(self.username, self.password)
161 + except ldap.LDAPError as error:
162 + self.error(error)
163 + return False
164 +
165 + self.alive = True
166 + return True
167 +
168 + def reconnect(self):
169 + self.disconnect()
170 + return self.connect()
171 +
172 + def check(self):
173 + if not HAS_LDAP:
174 + self.error("'python-ldap' package is needed")
175 + return None
176 +
177 + return self.connect() and self.get_data()
178 +
179 + def get_data(self):
180 + if not self.alive and not self.reconnect():
181 + return None
182 +
183 + data = dict()
184 + for key in SEARCH_LIST:
185 + dn = SEARCH_LIST[key][0]
186 + attr = SEARCH_LIST[key][1]
187 + try:
188 + num = self.conn.search(dn, ldap.SCOPE_BASE, 'objectClass=*', [attr, ])
189 + result_type, result_data = self.conn.result(num, 1)
190 + except ldap.LDAPError as error:
191 + self.error("Empty result. Check bind username/password. Message: ",error)
192 + self.alive = False
193 + return None
194 +
195 + try:
196 + if result_type == 101:
197 + val = int(result_data[0][1].values()[0][0])
198 + except (ValueError, IndexError) as error:
199 + self.debug(error)
200 + continue
201 +
202 + data[key] = val
203 +
204 + return data
collectors/python.d.plugin/openldap/openldap.conf new
+74
@@ -0,0 +1,74 @@
1 +# netdata python.d.plugin configuration for openldap
2 +#
3 +# This file is in YaML format. Generally the format is:
4 +#
5 +# name: value
6 +#
7 +# There are 2 sections:
8 +# - global variables
9 +# - one or more JOBS
10 +#
11 +# JOBS allow you to collect values from multiple sources.
12 +# Each source will have its own set of charts.
13 +#
14 +# JOB parameters have to be indented (using spaces only, example below).
15 +
16 +# ----------------------------------------------------------------------
17 +# Global Variables
18 +# These variables set the defaults for all JOBs, however each JOB
19 +# may define its own, overriding the defaults.
20 +
21 +# update_every sets the default data collection frequency.
22 +# If unset, the python.d.plugin default is used.
23 +# postfix is slow, so once every 10 seconds
24 +update_every: 10
25 +
26 +# priority controls the order of charts at the netdata dashboard.
27 +# Lower numbers move the charts towards the top of the page.
28 +# If unset, the default for python.d.plugin is used.
29 +# priority: 60000
30 +
31 +# retries sets the number of retries to be made in case of failures.
32 +# If unset, the default for python.d.plugin is used.
33 +# Attempts to restore the service are made once every update_every
34 +# and only if the module has collected values in the past.
35 +# retries: 60
36 +
37 +# autodetection_retry sets the job re-check interval in seconds.
38 +# The job is not deleted if check fails.
39 +# Attempts to start the job are made once every autodetection_retry.
40 +# This feature is disabled by default.
41 +# autodetection_retry: 0
42 +
43 +# ----------------------------------------------------------------------
44 +# JOBS (data collection sources)
45 +#
46 +# The default JOBS share the same *name*. JOBS with the same name
47 +# are mutually exclusive. Only one of them will be allowed running at
48 +# any time. This allows autodetection to try several alternatives and
49 +# pick the one that works.
50 +#
51 +# Any number of jobs is supported.
52 +#
53 +# All python.d.plugin JOBS (for all its modules) support a set of
54 +# predefined parameters. These are:
55 +#
56 +# job_name:
57 +# name: myname # the JOB's name as it will appear at the
58 +# # dashboard (by default is the job_name)
59 +# # JOBs sharing a name are mutually exclusive
60 +# update_every: 1 # the JOB's data collection frequency
61 +# priority: 60000 # the JOB's order on the dashboard
62 +# retries: 60 # the JOB's number of restoration attempts
63 +# autodetection_retry: 0 # the JOB's re-check interval in seconds
64 +#
65 +# ----------------------------------------------------------------------
66 +# OPENLDAP EXTRA PARAMETERS
67 +
68 +# Set here your LDAP connection settings
69 +
70 +#username : "cn=admin,dc=example,dc=com" # The bind user with right to access monitor statistics
71 +#password : "yourpass" # The password for the binded user
72 +#server : 'localhost' # The listening address of the LDAP server
73 +#port : 389 # The listening port of the LDAP server
74 +#timeout : 1 # Seconds to timeout if no connection exists
\ No newline at end of file
collectors/python.d.plugin/python.d.conf
+2 -1
@@ -73,6 +73,7 @@ logind: no
73 nginx_log: no
74 # nsd: yes
75 # ntpd: yes
76 +# openldap: yes
77 # ovpn_status_log: yes
78 # phpfpm: yes
79 # postfix: yes
@@ -96,4 +97,4 @@ unbound: no
97 # uwsgi: yes
98 # varnish: yes
99 # w1sensor: yes
99 -# web_log: yes
100 +# web_log: yes
\ No newline at end of file