def main(sid, user, pwd, warning, critical):
    result = ''
    query = "select 1.0 valor from dual;"
    inicio = datetime.datetime.now()
    time.sleep(11)
    Db.single_int_query(user, pwd, sid, query)

    fim = datetime.datetime.now()
    if 'ORA-' in result:
        print 'Erro desconhecido ao executar a query: %s' % result
        exit(3)
    else:
        intervalo = fim-inicio
        tempo = intervalo.days*24*60*60*1000
        tempo += intervalo.seconds*1000
        tempo += intervalo.microseconds/1000

        perf_data = 'CONNECTION_TIME=%d' % tempo
        if (int(tempo) >= int(critical)) :
            print 'CRITICAL - Conexao demorou %d milisegundos | %s ' % (tempo, perf_data)
            exit(3)
        elif (int(tempo) >= int(warning)) :
            print 'WARNING - Conexao demorou %d milisegundos | %s ' % (tempo, perf_data)
            exit(2)
        else:
            print 'OK - Conexao demorou %d milisegundos | %s ' % (tempo, perf_data)
            exit(0)
 def archives_by_day(self):
     """
     Quantidade de archives gerados hoje
     :return:
     """
     query = "set head off \n \
             set feedback off \n \
             select trunc(count(*)/4) avg_archives from v$log_history \n \
             where trunc(sysdate,'DD') = trunc(first_time,'DD');"
     self.archives_day = Db.single_int_query(self.user, self.password, self.sid, query)
 def avg_archives_hour(self):
     """
     Calcula a media de archives por hora
     Pega a media de archives das ultimas 3 horas
     :return:
     """
     query = "set head off \n \
             set feedback off \n \
             select decode(trunc(count(*)/4),0,1,trunc(count(*)/4)) avg_archives from v$log_history \n \
             where trunc(first_time,'HH24') <= trunc(sysdate,'HH24') \n \
             and trunc(first_time,'HH24') >= trunc(sysdate,'HH24') - 3/24;"
     self.avg_archives = Db.single_int_query(self.user, self.password, self.sid, query)
 def current_archive_weight(self):
     """
     Verifica a media do tamanho de um unico
     archive
     :return:
     """
     query = "set head off \n \
             set feedback off \n \
             select nvl(avg(blocks*block_size),0) \n \
     from gv$archived_log h \n \
     where trunc(sysdate,'DD') = trunc(first_time,'DD');"
     self.avg_archive_weight = Db.single_int_query(self.user, self.password, self.sid, query)
 def archives_used_space(self):
     """
     Verifica o espaco utilizado pelos archives
     :return:
     """
     query = "set head off \n \
             set feedback off \n \
             select nvl(sum(blocks*block_size),0) \n \
              from gv$archived_log \n \
              where status IN ('A','X') \n \
              and deleted = 'NO' \n \
             AND archived = 'YES';"
     self.archives_used = Db.single_int_query(self.user, self.password, self.sid, query)