def getBloats( param=None ) : item_name = 'POSTGRES_' status = [] perfdata = '-' output = '' if param != None : check = param['check'] item_name = item_name + check.upper() warning = fac.getSizeFactor(param['warning']) critical = fac.getSizeFactor(param['critical']) query = getQuery(check,warning[1],warning[0]) results = sql.getSQLResult ( {'host': param['host'][0] , 'port' : param['port'][0], 'dbname': param['dbname'], 'user' : param['user'] ,'password' : param['password'] } ,query ) if results[0] == None : return '2' + ' ' + item_name + ' ' + '-' + ' ' + results[1] rows = results[1] if len(rows) > 0 : for row in rows : out_unit = '' if int(row[3]) >= int(critical[0]) : status.append(2) out_unit = [row[3] , critical[2] ] elif int(row[3]) >= int(warning[0]) : status.append(1) out_unit = [ row[3], warning[2] ] if perfdata == '-' : perfdata = row[0] + '=' + str(row[3]) + ';' + str(warning[0]) + ';' + str(critical[0]) output = '{0:s} has {1:s} {2:s} ({3:s})% worth of bloat'.format(row[0],str(row[3]), out_unit[1], str(row[2]) ) elif perfdata != '-' : perfdata = perfdata + '|' + row[0] + '=' + str(row[3]) + ';' + str(warning[0]) + ';' + str(critical[0]) output = output + ';{0:s} has {1:s} {2:s} ({3:s})% worth of bloat'.format(row[0],str(row[3]), out_unit[1], str(row[2]) ) status.append( st.getStatus( int(row[3]),int(warning[0]) , int(critical[0]) ) ) 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' if param != None : warning = fac.getSizeFactor( param['warning'] ) critical = fac.getSizeFactor( param['critical'] ) item_name = item_name + str(param['check']).upper() query = getQuery ( param['check'],warning[1],critical[1],warning[1] ,warning[0] ) results = sql.getSQLResult ( {'host': param['host'][0] , 'port' : param['port'][0], 'dbname': param['dbname'], 'user' : param['user'] ,'password' : param['password'] } ,query ) if results[0] == None : return '2' + ' ' + item_name + ' ' + '-' + ' ' + results[1] rows = results[1] if len(rows) > 0 : for row in rows : out_unit = '' if int(row[2]) >= int(critical[0]) : status.append(2) out_unit = [row[2] , critical[2] ] elif int(row[1]) >= int(warning[0]) : status.append(1) out_unit = [ row[1], warning[2] ] if perfdata == '-' : perfdata = row[0] + '=' + str(row[3]) + ';' + str(warning[0]) + ';' + str(critical[0]) output = '{0:s} is {1:d} {2:s} big'.format(row[0],out_unit[0],out_unit[1]) elif perfdata != '-' : perfdata = perfdata + '|' + row[0] + '=' + str(row[3]) + ';' + str(warning[0]) + ';' + str(critical[0]) output = output + ';{0:s} is {1:d} {2:s} big'.format(row[0],out_unit[0],out_unit[1]) status.sort( reverse=True ) return str(status[0]) + ' ' + item_name + ' ' + str(perfdata) + ' ' + output elif len(rows) == 0 : status.append(0) return str(status[0]) + ' ' + item_name + ' ' + str(perfdata) + ' ' + output