Article

AS/400 Network Monitor--code

Cory A.N. Schewaga
 
Source Code:
--------MonitorM CL-------------
Pgm                                                                    
/* ================================================================ =*/
/* =MonitorM   - Main Network Monitor Program                       =*/
/* =                                                                =*/
/* =This program sends a message to the e-mail relay, waits, then   =*/
/* =checks for the return e-mail.  If found, the program will       =*/
/* =continue as normal.  If a return is not encountered, a message  =*/
/* =will be sent to any e-mail address.                             =*/
/* =                                                                =*/
/* =This program will also call the device monitor program,         =*/
/* =MonitorD.                                                       =*/
/* =This will monitor the specific addresses and if a problem       =*/
/* =is encountered, the system will wait for the threshold for that =*/
/* =address, then send a message to any e-mail address.             =*/
/* =                                                                =*/
/* =                                                                =*/
/* =                                                                =*/
/* =                                                                =*/
/* = ============================================================== =*/
                                                                       
/* = ============================================================== =*/
/* = Declare Variables                                              =*/
/* = ============================================================== =*/
/* E-mail Read Counter */                                              
            Dcl        &RdCnt           *Dec  (10 0) (1)              
/* Main E-mail Loop Counter */                                         
            Dcl        &loopE           *Dec  (2 0) (1)               
/* E-mail Loop Constant */                                             
            Dcl        &LoopN           *Dec  (2 0)                   
/* E-mail Prime Time Loop Constant */                                  
            Dcl        &LoopP           *Dec  (2 0)                   
/* E-mail Off Hours Loop Constant */                                   
            Dcl        &LoopO           *Dec  (2 0)
/* Main Device Loop Counter */                                    
            Dcl        &LoopD           *Dec  (2 0)  (1)          
/* Device Loop Constant */                                        
            Dcl        &LoopDc          *Dec  (2 0)               
/* E-mail Down Flag */                                             
            Dcl        &DwnFlg          *Char (1)    ('U')        
/* E-mail Threshold */                                             
            Dcl        &ThrsHld         *Dec  (10 0) (1)          
/* Message Variable */                                            
            Dcl        &Msg             *Char (60)                
/* Date Variable */                                               
            Dcl        &Date            *Char (6)                 
/* Time Variable */                                               
            Dcl        &Time            *Char (6)                 
/* Off Hour Start Time Constant */                                
            Dcl        &STim            *Char (6)                 
/* Off Hour End Time Constant */
Dcl        &ETim            *Char (6)                    
                                                                      
/* = ============================================================= =*/
/* = Send the e-mail message then wait 60 seconds                   =*/
/* = ============================================================= =*/
 SndMsg:     If         ((&LoopE *EQ 1) *Or (&DwnFlg *Eq +            
                          'D')) Then(Do)                              
             SndDst     *LMSG +                                       
                          ToIntNet((Relayaccount@yoursite.com)) +      
                          DstD('Email Test') Msg(*NONE) +             
                          LongMsg('Email route test') Pty(*HIGH)      
             EndDo                                                    
             DlyJob     60                                            
                                                                      
/* = ============================================================= =*/
/* = Retreive the loop and off hour times                          =*/
/* = ============================================================= =*/
LoopVal:     RtvDtaAra  YourLib/NetMonPrim      &LoopP              
             RtvDtaAra  YourLib/NetMonOffh      &LoopO              
             RtvDtaAra  YourLib/NetMonDevl      &LoopDc             
             RtvSysVal  QTime                   &Time               
             RtvDtaAra  YourLib/NetEmailSS      &STim               
             RtvDtaAra  YourLib/NetEmailSE      &ETIM               
                                                                       
/* = ============================================================= =*/ 
/* = If it is off-hours, use the off-hour loop value,              =*/ 
/* = otherwise use the prime time loop value                       =*/ 
/* = ============================================================= =*/ 
 Loop:       If         ((&Time *Ge &STim) *And (&Time *Le +           
                          &ETim)) Then(ChgVar &LoopN &LoopO)           
                          Else (ChgVar &LoopN &LoopP)                  
                                                                       
/* = ============================================================= =*/ 
/* = If the loop counter is equal to the defined loop value, or    =*/
/* = the e-mail is down, check the e-mail system                   =*/ 
/* = ============================================================= =*/ 
             If         ((&LoopE *EQ &LoopN) *Or (&DwnFlg *Eq +        
                          'D')) Then(Do)                               
                                                                       
/* = ============================================================= =*/ 
/* = Calls MonitorE to check for return distributions              =*/ 
/* =  RdCnt should be Gt zero if there is a return distribution    =*/ 
/* = ============================================================= =*/ 
 CheckEmail: Call       YourLib/MonitorE &RdCnt                   
                                                                       
                                                                       
/* = ============================================================= =*/ 
/* = The Threshold for the e-mail check is 1, so if the threshold  =*/ 
/* = is greater than one and there is a distribution, the e-mail   =*/ 
/* = has been restored                                             =*/ 
/* = ============================================================= =*/
Restored:   If         ((&ThrsHld *Gt 1) *And (&RdCnt *Gt 1)) +      
                          Then(Do)                                    
             RtvSysVal  QDate                      &Date              
             RtvSysVal  QTime                      &Time              
                                                                      
/* = ============================================================= =*/
/* = Send the e-mail UP message                                    =*/
/* = ============================================================= =*/
             ChgVar     &MSG ('EMAIL UP ' *CAT '  D: ' *CAT +         
                          &DATE *CAT '  T: ' *CAT &TIME)              
             SndDst     *LMSG +                                       
                          ToIntNet((Email Addresses)) +              
                          DstD('Email UP') Msg(*None) +                
                          LongMsg(&Msg)                                
                                                                       
/* = ============================================================= =*/ 
/* = Reset the e-mail check values                                 =*/ 
/* = ============================================================= =*/ 
             ChgVar     &THRSHLD (1)                                   
             CHGVAR     &DWNFLG  ('U')                                 
             Goto       Cont                                           
             EndDo                                                     
                                                                       
/* = ============================================================= =*/
/* = The Threshold for the e-mail check is 1, so if the threshold  =*/ 
/* = is equal to one and there is no distribution, the e-mail      =*/ 
/* = is down and this is the first indication that it is down      =*/ 
/* = ============================================================= =*/ 
 Failed:     If         ((&RdCnt *Eq 1) *And (&ThrsHld *Eq 1)) +       
                          Then(Do)                                     
             RtvSysVal  QDate                      &Date               
             RtvSysVal  QTime                      &Time               
                                                                       
/* = ============================================================= =*/ 
/* = Send the e-mail UP message                                    =*/ 
/* = ============================================================= =*/ 
             ChgVar     &Msg ('EMAIL DN ' *CAT '  D: ' *CAT +          
                          &DATE *CAT '  T: ' *CAT &TIME)               
             SndDst     *Lmsg +                                        
                          ToIntNet((Email Addresses)) +          
                          DstD('Email DN') Msg(*None) +            
                          LongMsg(&Msg)                            
             ChgVar     &THRSHLD  (&THRSHLD + 1)                   
             CHGVAR     &DWNFLG   ('D')                            
             EndDo                                                 
                                                                   
 Cont:       ChgVar     &RdCnt (1)                                 
EndDo                                                     
                                                                       
                                                                       
/* = ============================================================= =*/ 
/* = Next, call the Device Monitor Program                         =*/ 
/* = ============================================================= =*/ 
 Devices:    Call YourLib/MonitorD (&LoopD &LoopDc)               
                                                                       
/* = ============================================================= =*/ 
/* = Increment the loop counter.  If greater than defined loop     =*/ 
/* = counter, reset                                               =*/ 
/* = ============================================================= =*/ 
 Incr:       ChgVar     &LoopE (&LoopE + 1)                            
             ChgVar     &LoopD (&LoopD + 1)                            
                                                                       
             If         (&LoopE *Gt &LoopN) Then(Do)                   
             ChgVar     &LoopE (1)
EndDo                                                    
                                                                      
             If         (&LoopD *Gt &LoopDc) Then(Do)                 
             ChgVar     &LoopD (1)                                    
             EndDo                                                    
                                                                      
/* = ============================================================= =*/
/* = Loop                                                          =*/
/* = ============================================================= =*/
             Goto       SndMsg                                        
EndPgm


-------MonitorE CL--------------
Pgm        Parm(&RdCnt)                                                
/* = ============================================================== =*/
/* =MonitorE - Email Monitor Program                                =*/
/* = This program will query the distribution queue, increment the  =*/
/* = counter and delete the distribution.  The distribution will be =*/
/* = the return e-mail from the trace route through the e-mail system.												  =*/
/* =                                                                =*/
/* = This is called from MonitorM                                   =*/
/* =                                                                =*/
/* =                                                                =*/
/* = =============================================================  =*/
/* = ============================================================ =*/  
/* = Declare Variables                                            =*/  
/* = ============================================================ =*/  
             Dcl        &RdCnt            *DEC (10 0) (1)              
             DclF       YourLib/DstOutPf

/* = ============================================================ =*/
/* = Allocate the out file used in the QryDst command.  May be    =*/
/* = locked due to backups                                        =*/
/* = ============================================================ =*/
 Allocate:   AlcObj     Obj((YourLib/DstOutPf *File *Excl)) +     
                          Wait(*Cls)                                 
             MonMsg     (CPF1002 CPF3156) Exec(DO)                   
             DlyJob     120                                          
             Goto       Allocate                                     
             EndDo                                                   
/* = ============================================================ =*/
/* = Query the distribution for user QsysOpr into file DstOutPf.  =*/
/* = ============================================================ =*/
 QryFile:    QryDst     Usrid(QsysOpr Your400) +                       
                          OutFile(YourLib/DstOutPf)
/* = ============================================================ =*/
/* = Read through the distribution file, incrementing the counter =*/
/* = for each successful read                                     =*/
/* = Delete the distribution after each read                      =*/
/* = ============================================================ =*/
 Read:       RcvF       Dev(*File) RcdFmt(Oslin)                     
             MonMsg     Cpf0864 Exec(Goto Retrn)                     
             ChgVar     &RdCnt (&RdCnt + 1)                          
             DltDst     DstId(&LindId) UsrId(QsysOpr Your400)          
             Goto Read                                               
/* = ============================================================ =*/
/* = Deallocate the out file, clear it, then return to the main   =*/
/* =  program                                                     =*/
/* = ============================================================ =*/
 Retrn:
DeAllocate: DlcObj     Obj((YourLib/DstOutPf *File *Excl))    
             ClrPfm     YourLib/DstOutPf                       
                                                                  
             Return                                               
EndPgm
---------MonitorD CL----------------
Pgm Parm(&LoopD &LoopDc)                                                
/* = ============================================================== =*/ 
/* = MonitorD - Router Monitor Program                              =*/ 
/* =  This program will ping the devices defined in file CaDevDef.  =*/ 
/* =  If no response is encountered, a message will be sent to      =*/ 
/* =  the on-call phone and MIS.                                    =*/ 
/* =                                                                =*/ 
/* =  This is called from MonitorM                                  =*/ 
/* =                                                                =*/ 
/* = ============================================================== =*/ 
/* = ============================================================== =*/ 
/* = Declare Variables                                              =*/ 
/* = ============================================================== =*/ 
/* Email Message */
             Dcl        &Msg           *Char (60)    
/* Email Message Header */                   
             Dcl        &MsgHdr        *Char (30)
/* Date & Time*/
 Dcl        &Date          *Char (6)                       
             Dcl        &Time          *Char (6)                       
/* Loop counter and Loop constant */
             Dcl        &LoopD         *Dec  (2 0)                     
             Dcl        &LoopDc        *Dec  (2 0)                     
/* Physical File containing all the device definitions */
             DclF       YourLib/DeviceD                            
                                                                       
                                                                       
/* = ============================================================== =*/
/* = Read Through the Device Definition File                        =*/
/* = ============================================================== =*/
 Read:       RcvF       Dev(*File) RcdFmt(DevRec)                      
             MonMsg     Cpf0864 Exec(Goto CmdLbl(Retrn))               
                                                                       
/* = ============================================================== =*/
/* = DevFlg = Y to check, N to not check                            =*/
/* = ============================================================== =*/
             If         (&DevFlg *Eq 'Y') Then(Do)
/* = ============================================================== =*/
/* = Either check the status if the loop counter is up, or if the   =*/
/* =  Device is down (system into aggressive mode)                  =*/
/* = ============================================================== =*/
             If         ((&LoopD *Eq &LoopDc) *OR (&DevDfl *Eq +        
                          'D')) Then(Do)                                
                                                                        
/* = ============================================================== =*/ 
/* = Ping the IP address defined                                    =*/ 
/* = ============================================================== =*/ 
             Ping       &DevAdr MsgMode(*Verbose +                      
                          *Escape) NbrPkt(1) WaitTime(5)                
                                                                        
/* = ============================================================== =*/ 
/* = If the ping fails, check the threshold.                        =*/ 
/* =  If the device flag is less than the threshold, continue trying=*/ 
/* =  If the device flag is equal to the threshold, send the down   =*/ 
/* =   message                                                      =*/ 
/* = ============================================================== =*/ 
             MonMsg     (Tcp3210 Tcp3212) Exec(Do)
If         (&DevLpf *Lt &DevThr) Then(Do)                 
             RtvSysVal  QDate                   &Date                  
             RtvSysVal  QTime                   &Time                  
                                                                       
/* = ============================================================== =*/
/* = DeviceFix is an RPG program to maintain the individual device  =*/
/* =  flags.                                                        =*/
/* = ============================================================== =*/
             Call       YourLib/DeviceFlg (&DevAdr 'Y' +             
                          &Date &Time)                                 
             EndDo                                                     
                                                                       
 DeviceDn:   If         (&DevLpf *Eq &DevThr) Then(Do)                 
             RtvSysVal  QDate                   &Date                  
             RtvSysVal  QTime                   &Time                  
                                                                       
             Call       YourLib/DeviceFlg (&DevAdr 'Y' +
&Date &Time)                                 
                                                                       
/* = ============================================================== =*/
/* = Send down message                                              =*/
/* = ============================================================== =*/
             ChgVar     &Msg (&DevNam *Cat ' DN ' *Cat +               
                          &DevAdr *Cat ' D: ' *Cat &DevDat *Cat +      
                          'T: ' *Cat &DevTim)                          
             CHGVAR     &MsgHdr (&DevNam *Cat ' DN ')                  
                                                                       
 EmailMsg:   SndDst     *LMsg +                                        
                          ToIntNet((email addresses)) +              
                          DstD(&MsgHdr) Msg(*None) LongMsg(&Msg)       
                                                                       
 AS400Msg1:  If         (&DevMsg *Eq 'Y') Then(Do)                     
             SndNetMsg  Msg(&Msg) ToUsrId((yourdist your400))              
             EndDo                                                     
                                                                       
             EndDo                                                     
             Goto       Cont                                           
             EndDo                                                     
                                                                       
/* = ============================================================== =*/
/* = If Ping is successful and the device flag is greater than      =*/
/* =  then threshold (message was sent), send the up message        =*/
/* = ============================================================== =*/
 Reset:      RtvSysVal  QDate                   &Date                  
             RtvSysVal  QTime                   &Time                  
             If         (&DevLpf *Gt &DevThr) Then(Do)                 
             ChgVar     &MSG (&DevNam *Cat ' UP ' *Cat +               
                          &DevAdr *Cat ' D: ' *Cat &Date *Cat +        
                          'T: ' *Cat &Time)                            
             CHGVAR     &MsgHdr (&DevNam *Cat ' UP ')                  
             SndDst     *LMsg +                                        
                          ToIntNet((email addresses)) +               
                          DstD(&MsgHdr) Msg(*None) LongMsg(&Msg)        
                                                                        
 AS400Msg2:  If         (&DevMsg *Eq 'Y') Then(Do)                      
             SndNetMsg  Msg(&Msg) ToUsrId((MisNet Stoon))               
             EndDo                                                      
                                                                        
             EndDo                                                      
                                                                        
/* = ============================================================== =*/ 
/* = Reset the flags for the device                                 =*/ 
/* = ============================================================== =*/ 
             If         (&DevLpf *Ne 0) Then(Do)                        
             Call       YourLib/DeviceFlg (&DevAdr 'N' +
&Date &Time)                                  
             EndDo                                                      
             EndDo                                                      
             EndDo                                                      
                                                                        
/* = ============================================================== =*/ 
/* = Loop                                                           =*/ 
/* = ============================================================== =*/ 
 Cont:       Goto       CmdLbl(Read)                                    
                                                                        
                                                                        
/* = ============================================================== =*/ 
/* = Exit                                                           =*/ 
/* = ============================================================== =*/ 
 Retrn:      Return                                                     
EndPgm
----------DeviceFlg RPG-------------------
 **************************************************************  
 *   Pgm: DeviceFlg - Sets the loop flag in DeviceD if a problem,
 *        Resets it to 0 if the problem is resolved.             
 ****************************************************************
 ****************  CHANGES  *************************************
 * PERSON  *  DATE     *   CHANGE REQUIRED                       
 ****************************************************************
 *         *           *                                         
 ****************************************************************
 * = ========================================================== =
 * = Files Used                                                 =
 * = ========================================================== =
H                                                                
FDeviceD     E           K        DISK                           
C*                                                               
 * = ========================================================== =
 * = Main Program                                               =
 * = ========================================================== =
 * = ========================================================== =
 * = Chain to the Device File with the address passed in        =
 * = ========================================================== =
C           Addr      CHAINDeviceD              60               
C           *IN60     IFEQ *OFF                                  
 *                                                               
 * = ========================================================== =
 * = If the flag sent in is 'Y', a problem exists. Increment the=
 * = device counter, otherwise, the problem has been resolved,  =
 * = (or there isn't one) reset the device counter.             =
 * = ========================================================== =
C           Prob      IFEQ 'Y'                                   
C                     ADD  1         DEVLPF                      
C                     ELSE                                       
C                     Z-ADD0         DEVLPF                      
C                     MOVE *BLANKS   DEVDFL                      
C                     ENDIF                                      
 * = ========================================================== =
 * = If this is the first time that the outage is reported, log =
 * = the date and time of the original outage.                  =
 * = ========================================================== =
C           DEVLPF    IFEQ 1                                     
C                     MOVELPDate     DEVDAT                      
C                     MOVELPTime     DEVTIM                      
C                     MOVEL'D'       DEVDFL                      
C                     ENDIF                                      
C                     UPDATDEVREC                                
C                     ENDIF                                      
C                     SETON                     LR               
 *                                                               
 * = ========================================================== =
 * = Subroutines                                                =
 * = ========================================================== =
C           *INZSR    BEGSR                                      
 *                                                               
 * = ========================================================== =
 * = Define all the variables used in the program               =
 * = ========================================================== =
C           *LIKE     DEFN DEVADR    Addr                       
C           *LIKE     DEFN DEVADR    Prob                       
C           *LIKE     DEFN DEVDAT    PDate                       
C           *LIKE     DEFN DEVTIM    PTime                      
 *                                                               
 * = ========================================================== =
 * = Parameters Passed in (Device IP Address, Problem Flag,     =
 * =  Outage Date and Time.                                     =
 * = ========================================================== =
C           *ENTRY    PLIST                                      
C                     PARM           Addr                       
C                     PARM           Prob                        
C                     PARM           PDate                        
C                     PARM           PTime                        
C                     ENDSR

---------DeviceD DDS---------------
* = ========================================================= =
* = DeviceD - Device Definitions File                         =
* = Used in the MonitorD CL and the DeviceFlg RPG.  This file =
* = contains all the device definitions that will be checked. =
* =                                                           =
* =                                                           =
* =                                                           =
* = ========================================================= =
A          R DEVREC                                             
* IP Address                                                   
A            DEVADR        16     TEXT('ADDRESS')          
* Device Name                                                  
A            DEVNAM         8     TEXT('NAME')             
* Check Flag (Y - Device is checked, N - Device is skipped)    
A            DEVFLG         1     TEXT('CHECK FLAG (Y/N)') 
* Device outage threshold                                      
A            DEVTHR         1  0  TEXT('THRESHOLD')          
* Device Loop Flag, used to determine if the threshold has       
*  been surpassed or not                                         
A            DEVLPF         1  0  TEXT('LOOP FLAG - INTERNAL')
* Initial Date of outage                                         
A            DEVDAT         6     TEXT('DOWN DATE (MMDDYY)') 
* Initial Time of outage                                         
A            DEVTIM         6     TEXT('DOWN TIME (HHMMSS)') 
* Down Flag - used to determine if in aggressive mode            
A            DEVDFL         1     TEXT('DOWN FLAG D-DOWN, BLANK - Up')
* Break Message Flag - if set to Y, will send a break message to AS/400
*  Distribution list
A            DEVMSG         1     TEXT('BREAK MESSAGE Y or BLANK - No')
A          K DEVADR

--------StartNet CL----------------
PGM                                                                     
/* *************************************************************** */   
/* STARTNET   - CL LINKED TO COMMAND OF SAME NAME                  */   
/*  SUBMITS THE MonitorM NETWORK MONITOR PROGRAM                   */   
/*                                                                 */   
/*                                                                 */   
/* *************************************************************** */   
                                                                        
                                                                        
 SUBMT:      SBMJOB     CMD(CALL PGM(YourLib/MonitorM)) +            
                          JOB(NETMONITOR) JOBD(YourJobd) JOBQ(QCTL) +    
                          USER(YourID) LOG(4 0 *SECLVL) +              
                          SBMFOR(*CURRENT) JOBMSGQMX(10) +              
                          JOBMSGQFL(*WRAP)                              
                                                                        
 END:        RETURN                                                     
ENDPGM

---------StartNet CMD----------
CMD        PROMPT('Start Network Monitor')

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: