remove pynag from check ipa replica
This commit is contained in:
parent
c90cf15dc4
commit
c05bcd289f
1 changed files with 22 additions and 27 deletions
|
@ -16,39 +16,34 @@
|
|||
# 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
|
||||
import ldap, sys
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-u', help="ldap uri", dest="uri")
|
||||
parser.add_argument('-D', help="bind DN", dest="binddn")
|
||||
parser.add_argument('-w', help="bind password", dest="bindpw")
|
||||
opt = parser.parse_args()
|
||||
|
||||
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')
|
||||
if not opt.uri:
|
||||
parser.error('-u (uri) argument is required')
|
||||
|
||||
try:
|
||||
l = ldap.initialize(plugin.options.uri)
|
||||
l = ldap.initialize(opt.uri)
|
||||
|
||||
if plugin.options.binddn:
|
||||
l.bind_s(plugin.options.binddn, plugin.options.bindpw)
|
||||
if opt.binddn:
|
||||
l.bind_s(opt.binddn, opt.bindpw)
|
||||
|
||||
replication = l.search_s('cn=config',
|
||||
ldap.SCOPE_SUBTREE,
|
||||
'(objectclass=nsds5replicationagreement)',
|
||||
['nsDS5ReplicaHost', 'nsds5replicaLastUpdateStatus'])
|
||||
except Exception as e:
|
||||
plugin.status(critical)
|
||||
plugin.add_summary("Unable to initialize ldap connection: %s" % (e))
|
||||
plugin.exit()
|
||||
|
||||
# critical
|
||||
print(f"CRITICAL - Unable to initialize ldap connection: {e}")
|
||||
sys.exit(2)
|
||||
|
||||
# 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].decode('utf-8')
|
||||
code = status[:2]
|
||||
if status.startswith('Error ('):
|
||||
|
@ -59,16 +54,16 @@ for rhost in replication:
|
|||
code = status[:status.find(' ')]
|
||||
|
||||
if code == '0':
|
||||
plugin.status(ok)
|
||||
print(f"OK - Replica Status: {(rhost[1]['nsDS5ReplicaHost'][0], rhost[1]['nsds5replicaLastUpdateStatus'][0])}")
|
||||
sys.exit(0)
|
||||
elif code == '1':
|
||||
# Busy Replica is not an error, its "unknown" (but its "ok" for now)
|
||||
plugin.status(ok)
|
||||
print(f"OK - Replica Status: {(rhost[1]['nsDS5ReplicaHost'][0], rhost[1]['nsds5replicaLastUpdateStatus'][0])}")
|
||||
sys.exit(0)
|
||||
else:
|
||||
plugin.status(critical)
|
||||
sys.exit(2)
|
||||
|
||||
if not len(replication):
|
||||
plugin.add_summary("Warning: No replicas found")
|
||||
plugin.status(warning)
|
||||
|
||||
plugin.exit()
|
||||
print(f"Warning - No replicas found")
|
||||
sys.exit(1)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue