Script para gerar um resultado em XML

Esse script foi criado para alertar
em caso de existir um processo elevado no Oracle e preventivamente manda um SMS
antes que o problema ocorra. O serviço de envio é através da empresa DACI.

--// Chamada da SP

EXECUTE SP_DBA_PROCESSOS_SMS
('11XXXXXX','XXXXX','XXXXX' );


--// Cria um diretório de destino do arquivo

create directory ARQSYS as 'D:\BACKUP\HISTRAINING'

--// Procedure

create or replace PROCEDURE SP_DBA_PROCESSOS_SMS (
  telefone1  IN  STRING :='',
  telefone2  IN  STRING :='',
  telefone3  IN  STRING :='',
  telefone4  IN  STRING :='',
  telefone5  IN  STRING :=''  
)
IS
      arquivo_saida   UTL_File.File_Type;
     
strSQL          VARCHAR2(8000);
      nivel          
VARCHAR2(60);
     
servidor        VARCHAR2(200); 
     
mensagem       
VARCHAR2(200);   
      qtdeProcess     INT;

BEGIN 

     
strSQL        := '';
     
nivel         := '';
      servidor      :=
'SENIOR - DBPROD'; 
      mensagem      :=
'';   
      qtdeProcess   := 0;

  arquivo_saida :=
UTL_File.Fopen('ARQSYS','result.xml', 'W');     
 
  --// Atribui o resultado da query na variável 
  SELECT COUNT(*) INTO qtdeProcess FROM V$PROCESS;
 
  IF qtdeProcess > 800 THEN
    nivel := 'Moderado';
  END IF;
 
  IF qtdeProcess > 1000 THEN
    nivel := 'Alto';
  END IF;

  mensagem := 'Alerta: ''' nivel ''' - Quantidade de processos no
servidor (''' servidor '''): ''' TO_CHAR(qtdeProcess);
 
  IF qtdeProcess > 800 THEN
      
        strSQL := '<?xml
version="1.0"
encoding="iso-8859-1"?><gatewaydaci> 
<head>   <data service="sendmessage"
schedule="" type="1" text=""
filenumber="243268" /> </head>  <message>';
       
        IF (telefone1 IS NOT NULL) THEN
            strSQL :=
strSQL '' '<data number="''' telefone1 '''" text="'''
mensagem '''" idauthentication="" sequencer=""
iduser="" />';
        END IF;
     
        IF (telefone2 IS NOT NULL) THEN
            strSQL :=
strSQL '' '<data number="''' telefone2 '''" text="'''
mensagem '''" idauthentication="" sequencer=""
iduser="" />';
        END IF;
     
        IF (telefone3 IS NOT NULL) THEN
            strSQL :=
strSQL '' '<data number="''' telefone3 '''" text="'''
mensagem '''" idauthentication="" sequencer=""
iduser="" />';
        END IF;
     
        IF (telefone4 IS NOT NULL) THEN
            strSQL :=
strSQL '' '<data number="''' telefone4 '''" text="'''
mensagem '''" idauthentication="" sequencer=""
iduser="" />';
        END IF;
     
        IF (telefone5 IS NOT NULL) THEN
            strSQL :=
strSQL '' '<data number="''' telefone5 '''" text="'''
mensagem '''" idauthentication="" sequencer=""
iduser="" />';
        END IF;
     
        strSQL := strSQL ''
'</message></gatewaydaci>';
END IF;
UTL_File.Put_Line(arquivo_saida, strSQL);
UTL_File.Fclose(arquivo_saida);
END;