Create a PSMP monitoring service

Create a PSMP monitoring service

90
Created On 11/10/26 10:57 AM - Last Modified 11/10/26 15:52 PM


Objective


1.     Prerequisites:

• netstat utility

• Root right

• The two scripts:

o Verification script

o Service script

 

  1. 2.     Tools and verification:
  1. netstat installation:                                     « yum install nc »
  2. listening port declaration:                          « nc -4 -k --listen 5555 --keep-open & »
  3. Validation that the port is listening:         « netstat -anlp |grep 5555 »



Environment


Privileged Access Manager (PAM, self-hosted);Privilege Cloud PSMP

Procedure


3.     Monitoring script creation

a) Created the survpsmp.sh file: vi /usr/lib/systemd/system/survpsmp.sh

b) Then copy the script below

c) Make the script executable ”chmod + x /usr/lib/systemd/system/survpsmp.sh”

script survpsmp.sh

 

#!/bin/bash

if [ $1 = start ]; then

logger "start psmpmonitoring custom service"

logger "file is in /usr/lib/systemd/system/survpsmp.sh "

logger "Open custom port 5555"

 

nc -4 -k --listen 5555 --keep-open &

sleep 2s

check=1

 

#logger $check

logger "waiting psmpsrv crash"

 

while ((check!=20))

do

   sleep 1m

   systemctl status psmpsrv -l| grep -m 1 "Error:.*ITAC" && ((check=20)) || ((check=10))

#   logger $check

done

 

logger "Close custom port 5555 automatically"

#logger $check

kill -9 $(lsof -t -i:5555)

 

exit 0

fi

if [ $1 = stop ]; then

logger "Close custom port 5555 manually"

/usr/bin/kill -9 $(lsof -t -i:5555)

/usr/bin/kill -9 $2

exit 0

fi

 

Warning: In order not to saturate the system logs, you can disable "logger $ check" and “logger "waiting psmpsrv crash"” in the loop.

 

4.     Service creation:

Created the cybermonitor.service file: vi /usr/lib/systemd/system/cybermonitor.service

Then copy the script below

cybermonitor.service

 

 

[Unit]

Description=Monitor for Psmp

After=psmpsrv.service network.target

Requires=psmpsrv.service

 

[Service]

Type=simple

ExecStart=/usr/lib/systemd/system/survpsmp.sh start

ExecStop=/usr/lib/systemd/system/survpsmp.sh stop $MAINPID

 

[Install]

WantedBy=multi-user.target

 

 

 

5.     Service declaration

Create the symbolic link

ln -s /usr/lib/systemd/system/cybermonitor.service /etc/systemd/system/multi-user.target.wants/cybermonitor.service

Activate the service when the server starts

systemctl enable '/etc/systemd/system/multi-user.target.wants/cybermonitor.service '

Reload the systemctl daemon

'systemctl daemon-reload'

 

6.     Validation

a.  Nominal state

 

The service psmpsrv is Up and running

The new service cybermonitor is up and running too.

In the message log.

The port for the LB is open,

Here the port « 5555 »

 

 

b.  Test 1 Stopping the psmpsrv service

 

 

Stopping the psmpsrv service

The monitoring service also stops.

 

 

 

 

Be careful when restarting the service, make sure that the monitor is also started

 

 

c. Test 2: Stop the Vault's connections

 

Stop the Vault's connections

:

 

The script detects the connection error

Port 5555 is closed

 

 

7.     Useful commands

Remove symbolic link

rm '/etc/systemd/system/multi-user.target.wants/monitorpsmp.service'

Validé par yes

Service activation

systemctl enable cybermonitor.service

Service deactivation

systemctl disable cybermonitor.service

List of service

systemctl list-units --type=service

Detail of a service

Systemctl cat psmpsrv

List of dependencies of a service

systemctl list-dependencies psmpsrv

 



Actions
  • Print
  • Copy Link

    https://knowledgebase.paloaltonetworks.com/KCSArticleDetail?id=kA1hj0000000o6VCAQ&lang=en_US&refURL=http%3A%2F%2Fknowledgebase.paloaltonetworks.com%2FKCSArticleDetail