HEX
Server: LiteSpeed
System: Linux s3604.bom1.stableserver.net 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64
User: dmstechonline (1480)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: //lib64/nagios/plugins/check_a2_saltmaster_api.sh
#!/bin/bash

# Initialize variables
exit_code=0
output=""

# Check salt-master status
salt_master_status=$(systemctl is-active salt-master 2>/dev/null)
salt_master_ports_status=$(netstat -lntu | grep -E -c ":(4505|4506).*LISTEN")

if [ "$salt_master_status" != "active" ]; then
  output+="check_saltmaster_status - Saltmaster is not running. "
  exit_code=2
fi

if [ "$salt_master_ports_status" -ne 2 ]; then
  output+="check_saltmaster_ports_status - Ports 4505/4506 are not listening. "
  exit_code=2
fi

# Check salt-api status
salt_api_status=$(systemctl is-active salt-api 2>/dev/null)
salt_api_ports_status=$(netstat -lntu | grep -E -c ":8000.*LISTEN")

if [ "$salt_api_status" != "active" ]; then
  output+="check_salt-api_status - Salt-api is not running. "
  exit_code=2
fi

if [ "$salt_api_ports_status" -ne 1 ]; then
  output+="check_salt-api_port_status - Port 8000 is not listening. "
  exit_code=2
fi

# If everything is fine
if [ "$exit_code" -eq 0 ]; then
  output="OK - Saltmaster and Salt-api services are running with correct ports open."
fi

# Print final output and exit with the highest severity found
echo "$output"
exit $exit_code