Enable JAVA SNC Certificate monitoring in FRUN

As part of many SAP landscapes, Secure Network Communication (SNC) is used to establish secure communication between ABAP and Java systems. If your environment is running with SNC-based communication between ABAP and ME/MII Java systems using SNC certificates stored in Java security directory.

While SAP Focused Run (FRUN) provides extensive monitoring capabilities, we identified a monitoring gap: there is no standard FRUN template available to monitor validity of Java SNC certificates. This means an expired certificate could go unnoticed until communication failures begin occurring between connected systems.

To address this gap, we developed a custom monitoring solution in SAP Focused Run that automatically tracks Java SNC certificate validity, calculates remaining days until expiration, and generates alerts before certificate expires.

Business Challenge

Communication between ABAP and Java systems relies on SNC certificates for secure authentication and encryption.

Java SNC certificate was deployed in the following location:
/usr/sap//J**/sec/SAPSNCS.pse

Although certificate is critical for secure communication, there was no proactive monitoring mechanism available in Focused Run to track its validity.

This created following risks:

Unplanned certificate expiration
ABAP to Java communication failures
Potential business process disruption
Manual monitoring effort
Lack of centralized visibility

Objective was therefore to provide proactive monitoring and alerting through SAP Focused Run.

Solution Overview

Implemented solution performs following functions:

Reads SNC certificate from Java PSE file.
Extracts certificate expiry date.
Calculates number of days remaining before expiration.
Generates output in JSON format.
Sends value to Focused Run through a custom metric.
Raises alerts when configured thresholds are reached.

Architecture Overview

SAPSNCS.pse
│
▼
sapgenpse export_own_cert
│
▼
OpenSSL Certificate Parsing
│
▼
Remaining Days Calculation
│
▼
JSON Output Generation
│
▼
FRUN Custom Metric
│
▼
Alerting & Notification

SNC Certificate Location

SNC certificate used by the Java system is stored in:
/usr/sap//J*/sec/SAPSNCS.pse

This PSE file contains the certificate information required for SNC communication.

Extracting Certificate Expiry Date

SAP utility sapgenpse can export certificate directly from PSE file.

sapgenpse export_own_cert -p SAPSNCS.pse | openssl x509 -noout -enddate

Example output: notAfter=Sep 29 15:45:21 2027

This date is then used to calculate remaining certificate validity.

Custom Monitoring Script

Following shell script was developed to calculate remaining days before certificate expiry.

#!/bin/bash
SAPGENPSE=”sapgenpse”
PSE_FILE=”SAPSNCS.pse”
expiry_date=$(
$SAPGENPSE export_own_cert -p “$PSE_FILE” 2>/dev/null |
openssl x509 -noout -enddate |
cut -d= -f2
)
 
expiry_epoch=$(date -d “$expiry_date” +%s)
current_epoch=$(date +%s)
 
diff_days=$(( (expiry_epoch – current_epoch) / 86400 ))
 
echo “{“type”:”integer”,”name”:”NumDays”,”value”:$diff_days}” \

/tmp/NUMDAYS.json

Sample Output

generated JSON file contains the certificate validity in days.

JSON
{
“type”:”integer”,
“name”:”NumDays”,
“value”:30
}

This output can be consumed directly by SAP Focused Run custom monitoring metrics.

Creating a Custom Metric in FRUN

Step 1: Create a Custom Monitoring Script

Deploy the script on the managed host where SAPSNCS.pse exists.

Example location:

Shell

/usr/sap/SID/J**/sec/calc_sapsnc_validity.sh

Step 2: Configure Simple Diagnostics Agent Script Metric

Create a new metric.

Example:

ParameterValue
Metric NameSNC Certificate Validity
Collection TypeScript
Scriptcalc_sapsnc_validity.sh
JSON AttributeNumDays
Metric TypeNumeric

Custom agent metric was configured in SAP Focused Run to collect generated JSON value.

Metric periodically collects remaining validity days and displays them centrally in FRUN monitoring dashboards.

This provides sufficient lead time for certificate renewal activities before the certificate reaches its expiration date.

Monitoring Benefits

This implementation delivers several operational benefits:

Closes a monitoring gap in SAP Focused Run Provides centralized certificate visibility

Closes a monitoring gap in SAP Focused Run
Provides centralized certificate visibility
Eliminates manual certificate validation checks
Enables proactive alerting
Reduces risk of ABAP-Java communication failures
Improves overall operational readiness
Prevents service disruptions caused by expired SNC certificates

Lessons Learned

During implementation, one challenge encountered was script compatibility after transferring files from Windows to Linux systems. Script initially contained Windows CRLF line endings, resulting in execution errors.

Converting script to UNIX format resolved the issue:
dos2unix calc_sapsnc_validity.sh

Conclusion

Java SNC communication is a critical component for secure integration between ABAP and Java systems. Since SAP Focused Run does not provide a standard monitoring template for Java SNC certificate validity, organizations may lack visibility into upcoming certificate expirations.

By implementing a lightweight custom monitoring solution using sapgenpse, OpenSSL, and SAP Focused Run custom metrics, we successfully introduced proactive monitoring and alerting for Java SNC certificates.

This approach is simple to implement, easy to maintain, and significantly reduces risk of communication outages caused by expired SNC certificates.

Have you implemented custom certificate monitoring in SAP Focused Run or SAP Solution Manager? Feel free to share your experience and monitoring approaches in the comments.

Creating a Custom Metric to Check SAPRouter SNC Certificate Expiry

This metric and script checks the SAPRouter SNC certificate expiry and gives an alert depending on how many days left until expiry.

Define SAProuter in Focused Run LMDB

Prerequisite: Make sure you have installed the SAP Host Agent and performed Outside Discovery on the SAPRouter host.

Go to the LMDB of you Focused Run system, then go to Single Customer Network:

Switch Namespace and go to “Technical Systems” and choose “Unspecific Standalone Application System” from the drop-down, then hit Create.

Enter:

Enter the Extended SID:

Add Software Component Version:

Search on the software, and then select the correct release, then Add. E.g.:

Save

Add Installation Path and Required LMDB Attributes. NOTE: Find out the relevant software installation path of the SAPRouter on the server.

Perform Simple System Integration.

Configure Script and Custom SAPHostCtrl Operation

Prerequisite: The script requires the SAPRouter SNC Certificate to be properly installed, and the PSE credentials in the cred_v2 file for the account that runs the SAPRouter service.

A script is scheduled to run daily as the same user that runs the SAPRouter service. The script reads the expiry date of the from the PSE and writes it to a file in JSON format so that the FRUN metric can read and interpret it. The script by default has SAPRouter home directory as /usr/sap/saprouter or <drive>:\usr\sap\saprouter, and it can be changed. This will be denoted as <SAPROUTER_HOME>. The PSE file variable can also be changed.

Linux/Unix

Create a new executable file in the SAPRouter home directory and copy the code in Appendix A. Ensure it is owned and executable by the user that runs the SAPRouter service and belongs to group sapsys. E.g.,

chown <saprouter user>:sapsys saprouter_expiry_days.sh
chmod 744 saprouter_expiry_days.sh

In the script, adjust the following variables:

  • SAPROUTER_HOME
  • SECUDIR (The SECUDIR folder is where the PSE file resides)
  • SAPROUTER_USER
  • PSE

Test the Script. Switch to the user that runs the SAPRouter service, then execute the script:

/usr/sap/saprouter/saprouter_expiry_days.sh

Look for file NUMDAYS.json. It should contain e.g.:

{type:integer, name:NumDays, value:136}

Schedule script in the root crontab as follows:

# Run SAProuter SNC Certificate expiry check
00 09 * * * su - <saprouter user> -c /usr/sap/saprouter/saprouter_expiry_days.sh

Windows

Create a batch file (*.bat) in the SAPRouter home directory. In the script, adjust the following variables:

  • SAPROUTER_HOME
  • SECUDIR (The SECUDIR folder is where the PSE file resides)
  • PSE

Test the Script. Logon as the user that runs the SAPRouter service. Right-click on the bat script and “run as Administrator”. Alternatively, if you are not logged as the SAPRouter service account, you can “run-as” the user that runs the SAPRouter service and execute the script that way.

runas /user:<domain or hostname>\<SAPRouter service user> <SAPROUTER_HOME>\saprouter_expiry_days.bat

NOTE: The SAPRouter service user requires “Allow log on locally” user rights.

Look for file NUMDAYS.json. It should contain e.g.:

{type:integer, name:NumDays, value:136}

Schedule the Script. Open a command prompt as administrator. Execute the command:

SCHTASKS /CREATE /RU <DOMAIN>\<saprouter user> /RP <password> /SC DAILY /TN "Run SAPRouter SNC Certificate expiry check" /TR "C:\Windows\System32\cmd.exe /C \"<SAPROUTER_HOME>\saprouter_expiry_days.bat\"" /ST 09:00 /RL HIGHEST

Note: The start time e.g., 09:00 is in 24 hour format. You should see:

Run the new task to test it:

SCHTASKS /RUN /TN "Run SAPRouter SNC Certificate expiry check"

You should see:

Check the timestamp of the file NUMDAYS.json.

Create Custom Operation for saphostctrl

To load these values into Focused Run, a custom operation for saphostctrl needs to be created.

Linux/Unix

As Root: Create the following custom operations conf file:

/usr/sap/hostctrl/exe/operations.d/checksnccert.conf

Enter the following into the conf file:

Command: cat /usr/sap/saprouter/NUMDAYS.json
Description: Check number of days to SNC certificate expiry
ResultConverter: flat
Platform: Unix

Test the custom operation as follows:

/usr/sap/hostctrl/exe/saphostctrl -function ExecuteOperation -name checksnccert

Result should be:

Webmethod returned successfully
Operation ID: 06C635D6863A1EEDB6BC5C819EE199D7

----- Response data ----
description=Check number of days to SNC certificate expiry
{type:integer, name:NumDays, value:169}
exitcode=0

Windows

Create the following custom operations conf file:

C:\Program Files\SAP\hostctrl\exe\operations.d\checksnccert.conf

Enter the following into the conf file:

Command: FOR /F "tokens=* delims=" %x in (<SAPROUTER_HOME>\NUMDAYS.json) DO @echo %x
Description: Check number of days to SNC certificate expiry
ResultConverter: flat
Platform: Windows

In a Command Prompt as Administrator, test the custom operation as follows:

"C:\Program Files\SAP\hostctrl\exe\saphostctrl" -function ExecuteOperation -name checksnccert

Result should be:

Webmethod returned successfully
Operation ID: 00155D657F901EEDBCF9E32BC564F964

----- Response data ----
description=Check number of days to SNC certificate expiry
{type:integer, name:NumDays, value:360}
exitcode=0

Create Custom Alert in Focused Run

Create a new monitoring template for SAPRouter here:

Enter into Expert Mode. Create a new Alert with the following settings:

NOTE: If the tick box “Do not Group Individual Occurrences” is ticked, it will alert at each data collection regardless of its previous rating, and not only at a change of rating.

Create Custom Metric In Focused Run

Create a new Metric with the following settings:

Data Collection

All parameters of the Data Collector which are fixed should have the “Configure” box unticked, and the common parameters pre-filled with the correct values.

The “Custom Operation” parameter is the saphostctrl operation “checksnccert” created earlier. The “Metric Name” parameter is the name of the metric in the JSON output file produced by the script, which is “NumDays”.

Threshold

The threshold picks up the integer as returned by the script; if it falls to below or equals 10 days, then raise a yellow alert, if below or equals 5 days, then raise a red alert. Choose whatever threshold values suit you.

Assignment

Assign the Metric to the Alert:

Activate the Alert

Apply SAPRouter Template and Check Monitoring

TIP: Initially set the collection interval to 5 minutes and apply template to see whether it is collecting data. Then you can set the collection interval back to daily.

You should see this in the Monitoring Application:

Appendix A: saprouter_expiry_days.sh

#!/bin/bash
# Outputs the expiry date of the SNC Certificate and calculates the number of days
# If the number of days falls below threshold, it sends an alert
# Written by Tony Swietochowski

SAPROUTER_USER=saprouter
SAPROUTER_HOME=/usr/sap/saprouter
SECUDIR=$SAPROUTER_HOME/sec
PSE=local.pse
HOSTNAME=$(hostname -f)

# Check  for saprouter user
[[ ! "$USER"=="$SAPROUTER_USER" ]] && echo "This script must be run using the $SAPROUTER_USER user. Exiting." && exit 1

EXPIRYDATE=$(${SAPROUTER_HOME}/sapgenpse get_my_name -p $PSE -n validity 2>&1 | grep NotAfter | awk -F\( '{print$2}' | cut -c -6)
NUMDAYS=$(echo $(( ($(echo $(date --date="$EXPIRYDATE" +%s) - $(date -d $(date +%y%m%d) +%s)) )/86400 )))
# Above method based on https://stackoverflow.com/questions/4946785/how-to-find-the-difference-in-days-between-two-dates

echo $NUMDAYS > $SAPROUTER_HOME/NUMDAYS
echo \{type:integer, name:NumDays, value:$NUMDAYS\} > $SAPROUTER_HOME/NUMDAYS.json

Appendix B: saprouter_expiry_days.bat

@echo off

REM Outputs the expiry date of the SNC Certificate and calculates the number of days
REM If the number of days falls below threshold, it sends an alert
REM Written by Tony Swietochowski

set SAPROUTER_HOME=D:\usr\sap\saprouter
set SECUDIR=%SAPROUTER_HOME%\sec
set SNC_LIB=%SECUDIR%\sapcrypto.dll
set PSE=local.pse

for /f "tokens=2 delims=\" %%i in ('whoami') do set THISUSER=%%i
FOR /F "tokens=* USEBACKQ" %%F IN (`hostname`) DO (SET HOSTNAME=%%F)

chdir /d %SAPROUTER_HOME%

for /f "tokens=2 delims=(" %%a in ('%SAPROUTER_HOME%\sapgenpse.exe get_my_name -p %PSE% -n validity ^2^>^&^1 ^| findstr /l "NotAfter"') do set DATESTRING=(%%a

set expiry_year=20%DATESTRING:~1,2%
set expiry_month=%DATESTRING:~3,2%
set expiry_day=%DATESTRING:~5,2%

set current_year=%date:~-4%
set current_month=%date:~4,2%
set current_day=%date:~7,2%

set "from=%current_month%-%current_day%-%current_year%"
set "to=%expiry_month%-%expiry_day%-%expiry_year%"
echo Wscript.Echo DateDiff("d", "%from%", "%to%") > %TEMP%\tmp.vbs

for /f %%a in ('cscript /nologo %TEMP%\tmp.vbs') do set /a "numdays=%%a"

del %TEMP%\tmp.vbs

echo Number of days to SAPRouter certificate expiry: %numdays% > %SAPROUTER_HOME%\NUMDAYS.log
echo {type:integer, name:NumDays, value:%numdays%} > %SAPROUTER_HOME%\NUMDAYS.json

<< This blog was originally posted on SAP Focused Run Guru by Tony Swietochowski (DXC). Repost done with permission. >>