title: Cacti extend snmp by a custom script
body: <p>I have created a graph on Cacti about time to access to a specific page on our infrastructure with cacti and net-snmp.</p>
  
  <p>I have extended the capability with adding two new lines in file /etc/snmp/snmpd.conf :</p>
  
  <pre><code>extend stat_page1 /usr/local/bin/cacti/access_page.sh context1
  extend stat_page2 /usr/local/bin/cacti/access_page.sh context2
  </code></pre>
  
  <p>I have restarted the daemon snmpd to load this configuration.</p>
  
  <p>The script called is describe below, with other value, because for some reason, i can show this.</p>
  
  <pre><code>#!/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
  </code></pre>
  
  <p>If I launch the script manually i have this </p>
  
  <pre><code>$ /usr/local/bin/cacti/access_page.sh context2
  0.061
  $ /usr/local/bin/cacti/access_page.sh context1
  0.041
  </code></pre>
  
  <p>When I launch the script with snmpget, I have this result:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>All time, I get <strong>0.000</strong> value by <code>snmp</code> command and manually a real value.</p>
  
  <p>Could you help me about it?, please</p>