summaryrefslogtreecommitdiffstats
path: root/roles/nagios_client/files/scripts/check_ipa_replication
blob: 96ff469cf2b20f2603cf0c81779e48782912433a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/python 
# Source: https://github.com/opinkerfi/nagios-plugins/blob/master/check_ipa/check_ipa_replication
# Copyright 2013, Tomas Edwardsson 
# Copyright 2016, Patrick Uiterwijk
#
# This script is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import ldap
from pynag.Plugins import PluginHelper, critical, warning, ok

plugin = PluginHelper()

plugin.parser.add_option('-u', help="ldap uri", dest="uri")
plugin.parser.add_option('-D', help="bind DN", dest="binddn")
plugin.parser.add_option('-w', help="bind password", dest="bindpw")
plugin.parse_arguments()

if not plugin.options.uri:
    plugin.parser.error('-u (uri) argument is required')

try:
    l = ldap.initialize(plugin.options.uri)

    if plugin.options.binddn:
        l.bind_s(plugin.options.binddn, plugin.options.bindpw)

    replication = l.search_s('cn=config', 
        ldap.SCOPE_SUBTREE, 
        '(objectclass=nsds5replicationagreement)',
        ['nsDS5ReplicaHost', 'nsds5replicaLastUpdateStatus'])
except Exception, e:
    plugin.status(critical)
    plugin.add_summary("Unable to initialize ldap connection: %s" % (e))
    plugin.exit()


# Loop through replication agreements
for rhost in replication:
    plugin.add_summary("Replica %s Status: %s" % (rhost[1]['nsDS5ReplicaHost'][0], rhost[1]['nsds5replicaLastUpdateStatus'][0]))

    status = rhost[1]['nsds5replicaLastUpdateStatus'][0]
    code = status[:2]
    if status.startswith('Error ('):
        # IPA >=4.4.0
        code = status[status.find('(')+1:status.find(')')]
    else:
        # IPA <4.4.0
        code = status[:status.find(' ')]

    if code == '0':
        plugin.status(ok)
    elif code == '1':
        # Busy Replica is not an error, its "unknown" (but its "ok" for now)
        plugin.status(ok)
    else:
        plugin.status(critical)

if not len(replication):
    plugin.add_summary("Warning: No replicas found")
    plugin.status(warning)

plugin.exit()