I have created a graph on Cacti about time to access to a specific page on our infrastructure with cacti and net-snmp.
I have extended the capability with adding two new lines in file /etc/snmp/snmpd.conf :
extend stat_page1 /usr/local/bin/cacti/access_page.sh context1
extend stat_page2 /usr/local/bin/cacti/access_page.sh context2
I have restarted the daemon snmpd to load this configuration.
The script called is describe below, with other value, because for some reason, i can show this.
#!/bin/bash
domain="mydomain"
cookie_name="myCookie"
token="myToken"
if [ $# -eq 1 ]
then
if [ "$1" = "context1" ]
then
target_url="https://${domain}/${1}/page1.html"
TIME=$(curl -s -w "%{time_total}" -o /dev/null --cookie \"${cookie_name}=${token}\" ${target_url})
echo "$TIME"
elif [ "$1" = "context2" ]
then
target_url="https://${domain}/${1}/page2.html"
TIME=$(curl -s -w "%{time_total}" -o /dev/null --cookie \"${cookie_name}=${token}\" ${target_url})
echo "$TIME"
fi
If I launch the script manually i have this
$ /usr/local/bin/cacti/access_page.sh context2
0.061
$ /usr/local/bin/cacti/access_page.sh context1
0.041
When I launch the script with snmpget, I have this result:
snmpwalk -v2c -c myCommunity localhost NET-SNMP-EXTEND-MIB::nsExtendOutput2Table
NET-SNMP-EXTEND-MIB::nsExtendOutLine."stat_page1".1 = STRING: 0.000
NET-SNMP-EXTEND-MIB::nsExtendOutLine."stat_page2".1 = STRING: 0.000
All time, I get 0.000 value by snmp
command and manually a real value.
Could you help me about it?, please
Recently i had an issue with
snmp
and the execution script that call thecurl
command.This post was the closest of the problem when i searched some solutions.
I found a solution without disabling SELinux.
I am a newbie in SELinux but i solved this issue with some SELinux configuration, that could interest someone in the future.
Context :
Centos 7
Content of the configuration file for SNMP
/etc/snmp/snmpd.conf
:Solution:
When i looked for trace of the execution, with
sudo systemctl status snmpd
, some trace of curl were display :However, the server was running well at this port and the script executed outside SNMP worked well.
SELinux errors have been generated in audit logs :
Follow the step told by audit2allow comm apply to SELinux the new created module for
snmp_t
. Theaudit2allow -M
command generated two files snmpdcanopensocket.pp snmpdcanopensocket.te in your current directory. SELinux needs the .pp file to remap it's security rules.Restart the SNMP service with
sudo systemctl restart snmp
Now the curl in the script executed by SNMP behaves well and does not quit with a (7) error code.