Website/salt_status.sh
2024-03-20 17:41:57 -05:00

73 lines
2.9 KiB
Bash

#! /bin/bash
if ! crontab -l | grep -q "salt_status.sh"; then
echo -e "$(crontab -u root -l)\n*/5 * * * * /usr/local/bin/salt_status.sh > /var/lib/node_exporter/salt_status.prom 2>&1" | crontab -u root -
fi
if [ "$(command -v /bin/ss)" ]; then
dir=/bin
elif [ "$(command -v /usr/bin/ss)" ]; then
dir=/usr/bin
else
dir=/usr/sbin
fi
install_salt_status() {
{
touch /usr/local/bin/salt_status.sh
{
echo '#! /bin/bash'
echo '#####################################################'
echo '### ###'
echo '### Description: Expose metrics from salt-minion. ###'
echo '### ###'
echo '### Phil Connor contact@mylinux.work ###'
echo '### Version 1.3.3.122023 ###'
echo '### ###'
echo '#####################################################'
echo ''
echo '## Local Command Variables'
# shellcheck disable=SC2016
echo 'if [ ! "$(command -v salt-call)" ]; then'
echo ' cert=none'
echo 'else'
# shellcheck disable=SC2016,SC2028
echo ' cert=$(salt-call test.ping | grep '\''\bTrue\b'\'')'
echo 'fi'
echo ''
# shellcheck disable=SC2016,SC2028
echo "status=\$($dir/ss -nt | grep '\b4505\b')"
echo ''
echo '## Check If minion is connected to port 4505'
echo 'echo '\''# HELP minion_connection_status Shows if Salt-Minion is connected to Salt-Master.'\'' '
echo 'echo '\''# TYPE minion_connection_status gauge'\'' '
# shellcheck disable=SC2016
echo 'if [[ -n "${status}" ]]; then'
echo ' echo '\''minion_connection_status{status=""} 1'\'' '
echo 'else'
echo ' echo '\''minion_connection_status{status=""} 0'\'' '
echo 'fi'
echo ''
echo '## Check to see in minion can ping master'
echo 'echo '\''# HELP minion_ping_status Shows if Salt-Minion is able to ping Salt-Master.'\'' '
echo 'echo '\''# TYPE minion_ping_status gauge'\'' '
# shellcheck disable=SC2016
echo 'if [ $cert = none ]; then'
echo ' echo '\''minion_ping_status{status=""} 2'\'' '
# shellcheck disable=SC2016
echo 'elif [[ -n "${cert}" ]]; then'
echo ' echo '\''minion_ping_status{status=""} 1'\'' '
echo 'else'
echo ' echo '\''minion_ping_status{status=""} 0'\'' '
echo 'fi'
} > /usr/local/bin/salt_status.sh
chmod 755 /usr/local/bin/salt_status.sh
}
}
########################
#### Function Calls ####
########################
install_salt_status