Subroutine Service_Manager_Debugger_Intercept(Void)
/***********************************************************************************************************************

    This program is proprietary and is not to be used by or disclosed to others, nor is it to be copied without written
    permission from SRP Computer Solutions, Inc.

    Name        :   Service_Manager_Debugger_Intercept

    Description :   Handler program for the HTTP Debugger service module.

    Notes       :   Service handler for HTTP Requests that abort due to a Runtime Error and the Debugger Intercept
                    has been enabled.

    Parameters  :

    Metadata    :

    History     :   (Date, Initials, Notes)
        07/25/23    djs     Original programmer.
        06/04/25	djs		Added LSL note creation (and email forwarding) to notify OI_ADMIN users when invoked.

***********************************************************************************************************************/

#pragma precomp SRP_PreCompiler

$insert APP_INSERTS
$insert RTI_DEBUG_COMMON
$insert ENVIRON_CONSTANTS

Declare function   Environment_Services, Logging_Services, Environment_Services, GetCommandLine, Datetime
Declare subroutine Logging_Services, obj_Notes, Set_Env

Main:
	
	// Log event in .\LogFiles\ServiceManager\<Date> OEngine Log.csv
	LogPath      = Environment_Services('GetApplicationRootPath') : '\LogFiles\ServiceManager'
	LogDate      = Oconv(Date(), 'D4/')
	LogTime      = Oconv(Time(), 'MTS')
	LogFileName  = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : ' OEngine Log.csv'
	Headers      = 'Stored Proc Status' : @FM : 'Stored Proc Status Code' : @FM : 'Current Program' : @FM
	Headers     := 'Call Depth' : @FM : 'Line No' : @FM : 'Call Stack'
	objLog       = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, ',', Headers, '', False$, False$)
	LogData      = ''
	LogData<1>   = spStatus@
	LogData<2>   = spStatCode@
	LogData<3>   = curr_Program@
	LogData<4>   = callDepth@
	LogData<5>   = lineNo@
	LogData<6>   = callStack@
	Logging_Services('AppendLog', objLog, LogData, @RM, @FM, '', '', '')

	// Send an LSL message to FI admins to alert them. This is forward to their email address if configured in
	// their LSL_USERS record.
	CmdLine      = GetCommandLine()
	EngIndex     = Index(CmdLine, '/S=', 1)
	EngNo        = CmdLine[EngIndex + 3, 'F ']
	Server       = Environment_Services('GetServer')
	Recipients   = ''
	SentFrom     = 'SYSTEM'
	Subject      = 'Service Manager Debugger Intercept Invoked'
	Message      = OConv(Datetime(), 'DT2/^H')
	Message<2>   = 'RevEngineHost (OEngine) ':EngNo:' encountered a runtime error on server ':Server
	Message<3>   = 'Stored Procedure Status: ':spStatus@
	StatCodes    = spStatCode@
	Swap Char(0) with ',' in StatCodes
	Swap Char(23) with '' in StatCodes
	Message<4>   = 'Stored Procedure Status Code: ':StatCodes
	Message<5>   = 'Current Program: ':curr_Program@
	Message<6>   = 'Call Depth: ':callDepth@
	Message<7>   = 'Line No: ':lineNo@
	Message<8>   = 'Call Stack: ':\0D0A\:callStack@
	Swap @FM with \0D0A\ in Message
	Swap @VM with ',' in Message
	AttachWindow = ''
	AttachKey    = ''
	SendToGroup  = 'OI_SYSADMIN'

	Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
	obj_Notes('Create',Parms)

Return

