def getDefaults (check , warning , critical ) : if check == 'backends' : # only whole digits and percentages allowed, an or separator is also allowed return fac.getNumberPercentMix (warning, critical, '80%', '90%' ) elif check == 'wals' : # -- warning 70%Max count # -- critical 80%Max count return fac.getNumberPercentMix (warning, critical, '70%', '80%' ) elif check == 'autovacuum' or check == 'vacuum' or check == 'autoanalyze' or check == 'analyze': # -- warning = 1 week # -- critical = 2 weeks return fac.getTimeDefaults (warning, critical , '1wk', '2wks',0.8) elif check == 'table_bloat' or check == 'index_bloat' : # Warning and/or Critical must be provided return fac.warningAndOrCriticalProvided (warning,critical,0.8) elif check == 'table_size' or check == 'index_size' or check == 'database_size' : # warning and/or critical value must be supplied return fac.warningAndOrCriticalProvided (warning,critical,0.5) elif check == 'nonblocking' or check == 'blocking' : # --warning = 2min # critical = 3min return fac.getTimeDefaults (warning, critical , '1min', '2mins', 0.8) elif check == 'checkpoints' : # warning and/or critical value must be supplied return None elif check == 'replica_lag' : # -- warning = 5 wal files # -- critical = 10 wal files return fac.getNumberPercentMix (warning, critical, '5', '10' ) elif check == 'connections' : return {'warning':'dummy', 'critical' :'dummy'}
def getBloats( param=None ) : item_name = 'POSTGRES_' status = [] perfdata = '-' output = '' if param != None : check = param['check'] item_name = item_name + check.upper() dbnames = param.get('dbname') retval = fac.warningAndOrCriticalProvided (param.get('warning'),param.get('critical')) warning = [] critical = [] if retval != None : warning = retval.get('warning') critical = retval.get('critical') else : return '2' + ' ' + item_name + ' ' + '-' + ' ' + 'Invalid parameters supplied' query = getQuery(check) query = query.format(int(warning[1]),int(warning[0])) exclude_db = param.get('exclude_db') for db in exclude_db : if db in dbnames : dbnames.remove(db) for dbname in dbnames : results = sql.getSQLResult ( {'host': param['host'][0] , 'port' : param['port'][0], 'dbname': dbname, 'user' : param['user'] ,'password' : param['password'] } ,query ) if results[0] == None : return '2' + ' ' + item_name + ' ' + perfdata + ' ' + results[1] rows = results[1] if len(rows) > 0 : for row in rows : out_unit = '' status.append(st.getStatus(row[3] , warning[0] , critical[0]) ) if perfdata == '-' : perfdata = perf.getPerfStm (row[0],row[3],warning[0],str(critical[0])) output = '{0:s} has {1:s} {2:s} ({3:s})% worth of bloat'.format(row[0],str(row[3]), warning[2], str(row[2]) ) elif perfdata != '-' : perfdata = perfdata + '|' + perf.getPerfStm (row[0],row[3],warning[0],str(critical[0])) output = output + ';\n {0:s} has {1:s} {2:s} ({3:s})% worth of bloat'.format(row[0],str(row[3]), warning[2], str(row[2]) ) if perfdata != '-' : status.sort( reverse=True ) return str(status[0]) + ' ' + item_name + ' ' + str(perfdata) + ' ' + output else : return '0' + ' ' + item_name + ' ' + '-' + ' ' + 'OK'
def getRelationSizes( param=None ) : item_name = 'POSTGRES_' status = [] perfdata = '-' output = 'OK' warning = [] critical = [] if param != None : retval = fac.warningAndOrCriticalProvided (param.get('warning'),param.get('critical')) if retval != None : warning = retval.get('warning') critical = retval.get('critical') else : return '2' + ' ' + item_name + ' ' + '-' + ' ' + 'Invalid parameters passed !' item_name = item_name + str(param['check']).upper() col_name = 'table_name' query = getQuery ( param['check'],warning[1],warning[0] ) dbnames = param.get('dbname') exclude_db = param.get('exclude_db') for db in exclude_db : if db in dbnames : dbnames.remove(db) for dbname in dbnames : results = sql.getSQLResult ( {'host': param['host'][0] , 'port' : param['port'][0], 'dbname': dbname, 'user' : param['user'] ,'password' : param['password'] } ,query ) if results[0] == None : return '2' + ' ' + item_name + ' ' + perfdata + ' ' + str(results[1]) rows = results[1] if len(rows) > 0 : for row in rows : status.append( st.getStatus(row[1] , warning[0] , critical[0] ) ) if perfdata == '-' : perfdata = perf.getPerfStm (row[0],row[1],warning[0],critical[0]) output = '{0:s} is {1:d} {2:s} big'.format(row[0],row[1],warning[2]) elif perfdata != '-' : perfdata = perfdata + '|' + perf.getPerfStm (row[0],row[1],warning[0],critical[0]) output = output + ';\n {0:s} is {1:d} {2:s} big'.format(row[0],row[1],warning[2]) if perfdata != '-' : status.sort( reverse=True ) return str(status[0]) + ' ' + item_name + ' ' + str(perfdata) + ' ' + output else : return '0' + ' ' + item_name + ' ' + str(perfdata) + ' ' + output
def getRelationSizes(param=None): item_name = 'POSTGRES_' status = [] perfdata = '-' output = 'OK' warning = [] critical = [] if param != None: retval = fac.warningAndOrCriticalProvided(param.get('warning'), param.get('critical')) if retval != None: warning = retval.get('warning') critical = retval.get('critical') else: return '2' + ' ' + item_name + ' ' + '-' + ' ' + 'Invalid parameters passed !' item_name = item_name + str(param['check']).upper() col_name = 'table_name' query = getQuery(param['check'], warning[1], warning[0]) dbnames = param.get('dbname') exclude_db = param.get('exclude_db') for db in exclude_db: if db in dbnames: dbnames.remove(db) for dbname in dbnames: results = sql.getSQLResult( { 'host': param['host'][0], 'port': param['port'][0], 'dbname': dbname, 'user': param['user'], 'password': param['password'] }, query) if results[0] == None: return '2' + ' ' + item_name + ' ' + perfdata + ' ' + str( results[1]) rows = results[1] if len(rows) > 0: for row in rows: status.append(st.getStatus(row[1], warning[0], critical[0])) if perfdata == '-': perfdata = perf.getPerfStm(row[0], row[1], warning[0], critical[0]) output = '{0:s} is {1:d} {2:s} big'.format( row[0], row[1], warning[2]) elif perfdata != '-': perfdata = perfdata + '|' + perf.getPerfStm( row[0], row[1], warning[0], critical[0]) output = output + ';\n {0:s} is {1:d} {2:s} big'.format( row[0], row[1], warning[2]) if perfdata != '-': status.sort(reverse=True) return str(status[0]) + ' ' + item_name + ' ' + str( perfdata) + ' ' + output else: return '0' + ' ' + item_name + ' ' + str(perfdata) + ' ' + output