#!/usr/bin/python # check_nuodb_domain.py Nagios plugin # # Copyright (c) 2013, NuoDB, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # * Neither the name of NuoDB, Inc. nor the names of its contributors may # be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL NUODB, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import sys, getopt, pynuodb def main(argv): # Get broker (b, broker), domain user (d, domainuser) , password (p, passwd) try: opts, args = getopt.getopt(argv, "b:d:p:",["broker=", "domainuser=", "passwd="]) except getopt.GetoptError: print "check_nuodb_domain.py -b -d -p " sys.exit(2) # Also make sure we also have the right number of arguments from the input. if len(opts) != 3: print "check_nuodb_domain.py -b -d -p " sys.exit(2) # Set the variables based on the input arguments. for opt, arg in opts: if opt in ("-b", "--broker"): broker = arg elif opt in ("-d", "--domainuser"): domainuser = arg elif opt in ("-p", "--passwd"): passwd = arg from pynuodb.entity import Domain # Try to connect to the broker, and return critical if you can't try: d = Domain(broker, domainuser, passwd) except: print "NuoDB Critical - Unable to connect to broker." sys.exit(2) # Make sure that there's at least one database, # and that each database has at least one TE and one SM try: if len(d.databases) is 0: print "NuoDB Warning - No databases found in Domain." sys.exit(1) ndb = len(d.databases) for db in d.databases: smcount = 0 tecount = 0 for p in db.processes: if p.is_transactional: tecount +=1 else: smcount += 1 if smcount == 0: print "NuoDB Critical - No Storage Managers found for database " + str(db) + "." sys.exit(2) if tecount == 0: print "NuoDB Critical - No Transaction Engines found for database " + str(db) + "." sys.exit(2) finally: d.disconnect() if ndb == 1: print "NuoDB Ok - " + str(ndb) + " database in Domain." else: print "NuoDB Ok - " + str(ndb) + " databases in Domain." sys.exit(0) if __name__ == "__main__": main(sys.argv[1:])