create or replace procedure dba_app.monitora_sessions is
vServer VARCHAR2(30) := 'smtp.denilson.com.br';
vSender VARCHAR2(30) := '';
vDest VARCHAR2(100) := '';
vSubj VARCHAR2(50) := 'Verificar Sessão - Produção';
vMesg VARCHAR2(32000):='Verificar Sessão'||UTL_TCP.CRLF;
vManda NUMBER:=0;
l_mail_conn utl_smtp.connection;
BEGIN
l_mail_conn := utl_smtp.open_connection(vServer, 25);
utl_smtp.helo(l_mail_conn, vServer);
utl_smtp.mail(l_mail_conn, vSender);
utl_smtp.rcpt(l_mail_conn, vDest);
utl_smtp.open_data(l_mail_conn );
utl_smtp.write_data(l_mail_conn, 'Subject'||':'|| 'Verificar Sessao - Producao' || UTL_TCP.CRLF);
FOR I IN(select username, sid, serial#, trunc(last_call_et/60) dur
from v$session
where last_call_et > 20*60
and status = 'ACTIVE' )
LOOP
vManda := vManda +1;
vMesg:=vMesg||UTL_TCP.CRLF||rpad(i.username,20,' ' )||' '||'SID:'||' '||rpad(i.sid,5,' ') ||' '||'SERIAL#:'||' '||i.serial#||' '||'TEMPO:'||' '||i.dur||'Min '||UTL_TCP.CRLF;
END LOOP;
dbms_output.put_line(vManda);
if (vManda >= 1) then
utl_smtp.write_data(l_mail_conn,vMesg);
utl_smtp.close_data(l_mail_conn );
utl_smtp.quit(l_mail_conn);
end if;
EXCEPTION WHEN OTHERS THEN
NULL;
END;
/
-- Agendando execução Procedure
BEGIN
DBMS_SCHEDULER.create_job (
job_name => 'sys.monitor_sessions',
job_type => 'PLSQL_BLOCK',
job_action => 'begin monitora_sessions; end;',
start_date => SYSTIMESTAMP,
repeat_interval => 'freq=MINUTELY; INTERVAL=20',
end_date => NULL,
enabled => TRUE,
comments => 'Monitor Sessoes');
END;
/
vServer VARCHAR2(30) := 'smtp.denilson.com.br';
vSender VARCHAR2(30) := '
vDest VARCHAR2(100) := '
vSubj VARCHAR2(50) := 'Verificar Sessão - Produção';
vMesg VARCHAR2(32000):='Verificar Sessão'||UTL_TCP.CRLF;
vManda NUMBER:=0;
l_mail_conn utl_smtp.connection;
BEGIN
l_mail_conn := utl_smtp.open_connection(vServer, 25);
utl_smtp.helo(l_mail_conn, vServer);
utl_smtp.mail(l_mail_conn, vSender);
utl_smtp.rcpt(l_mail_conn, vDest);
utl_smtp.open_data(l_mail_conn );
utl_smtp.write_data(l_mail_conn, 'Subject'||':'|| 'Verificar Sessao - Producao' || UTL_TCP.CRLF);
FOR I IN(select username, sid, serial#, trunc(last_call_et/60) dur
from v$session
where last_call_et > 20*60
and status = 'ACTIVE' )
LOOP
vManda := vManda +1;
vMesg:=vMesg||UTL_TCP.CRLF||rpad(i.username,20,' ' )||' '||'SID:'||' '||rpad(i.sid,5,' ') ||' '||'SERIAL#:'||' '||i.serial#||' '||'TEMPO:'||' '||i.dur||'Min '||UTL_TCP.CRLF;
END LOOP;
dbms_output.put_line(vManda);
if (vManda >= 1) then
utl_smtp.write_data(l_mail_conn,vMesg);
utl_smtp.close_data(l_mail_conn );
utl_smtp.quit(l_mail_conn);
end if;
EXCEPTION WHEN OTHERS THEN
NULL;
END;
/
-- Agendando execução Procedure
BEGIN
DBMS_SCHEDULER.create_job (
job_name => 'sys.monitor_sessions',
job_type => 'PLSQL_BLOCK',
job_action => 'begin monitora_sessions; end;',
start_date => SYSTIMESTAMP,
repeat_interval => 'freq=MINUTELY; INTERVAL=20',
end_date => NULL,
enabled => TRUE,
comments => 'Monitor Sessoes');
END;
/
Comentários
Postar um comentário