Skip to content
Advertisement

How we can update MIB variables values dynamically in linux?

I have created one mib file where five variables are added. Also by using the following command

snmptranslate -m +GET-LATEST-SIGNALS-MIB -IR -On oversightInteger

I’m able to see the OID’s of the all varialbes.

After this by using “PASS protocol” I tried to get the data from the one variable with the help of following script file

#!/bin/sh -f

PLACE=".1.3.6.1.4.1.53864.1.1"
REQ="$2"    # Requested OID

#
#  Process SET requests by simply logging the assigned value
#      Note that such "assignments" are not persistent,
#      nor is the syntax or requested value validated
#
if [ "$1" = "-s" ]; then
  echo $* >> /tmp/passtest.log
  exit 0
fi

#
#  GETNEXT requests - determine next valid instance
#
if [ "$1" = "-n" ]; then
  case "$REQ" in
    $PLACE|             
    $PLACE.0|           
    $PLACE.0.*|         
    $PLACE.1)       RET=$PLACE.1.0 ;;     # netSnmpPassString.0

    $PLACE.1.*|         
    $PLACE.2|           
    $PLACE.2.0|         
    $PLACE.2.0.*|       
    $PLACE.2.1|         
    $PLACE.2.1.0|       
    $PLACE.2.1.0.*|     
    $PLACE.2.1.1|       
    $PLACE.2.1.1.*|     
    $PLACE.2.1.2|       
    $PLACE.2.1.2.0) RET=$PLACE.2.1.2.1 ;; # netSnmpPassInteger.1

    $PLACE.2.1.2.*|     
    $PLACE.2.1.3|       
    $PLACE.2.1.3.0) RET=$PLACE.2.1.3.1 ;; # netSnmpPassOID.1

    $PLACE.2.*|         
    $PLACE.3)       RET=$PLACE.3.0 ;;     # netSnmpPassTimeTicks.0
    $PLACE.3.*|         
    $PLACE.4)       RET=$PLACE.4.0 ;;     # netSnmpPassIpAddress.0
    $PLACE.4.*|         
    $PLACE.5)       RET=$PLACE.5.0 ;;     # netSnmpPassCounter.0
    $PLACE.5.*|         
    $PLACE.6)       RET=$PLACE.6.0 ;;     # netSnmpPassGauge.0

    *)              exit 0 ;;
  esac
else
#
#  GET requests - check for valid instance
#
  case "$REQ" in
    $PLACE.1.0|         
    $PLACE.2.1.2.1|     
    $PLACE.2.1.3.1|     
    $PLACE.3.0|         
    $PLACE.4.0|         
    $PLACE.5.0|         
    $PLACE.6.0)     RET=$REQ ;;
    *)              exit 0 ;;
  esac
fi

#
#  "Process" GET* requests - return hard-coded value
#
echo "$RET"
case "$RET" in
  $PLACE.1.0)     echo "string";    echo "Life, the Universe, and Everything"; exit 0 ;;
  $PLACE.2.1.2.1) echo "integer";   echo "42";                                 exit 0 ;;
  $PLACE.2.1.3.1) echo "objectid";  echo "$PLACE.99";                          exit 0 ;;
  $PLACE.3.0)     echo "timeticks"; echo "363136200";                          exit 0 ;;
  $PLACE.4.0)     echo "ipaddress"; echo "127.0.0.1";                          exit 0 ;;
  $PLACE.5.0)     echo "counter";   echo "42";                                 exit 0 ;;
  $PLACE.6.0)     echo "gauge";     echo "42";                                 exit 0 ;;
  *)              echo "string";    echo "ack... $RET $REQ";                   exit 0 ;;  # Should not happen
esac

After running the above script file I used the following command

snmpwalk -v2c localhost -c public .1.3.6.1.4.1.53864

and the output i got as follows

GET-LATEST-SIGNALS-MIB::oversightInteger.1.0 = STRING: "Life, the 
Universe, and Everything"
GET-LATEST-SIGNALS-MIB::oversightInteger.2.1.2.1 = Wrong Type 
(should be OCTET STRING): INTEGER: 42
GET-LATEST-SIGNALS-MIB::oversightInteger.2.1.3.1 = Wrong Type 
(should be OCTET STRING): OID: GET-LATEST-SIGNALS- 
MIB::oversightInteger.99
GET-LATEST-SIGNALS-MIB::oversightInteger.3.0 = Wrong Type (should 
be OCTET STRING): Timeticks: (363136200) 42 days, 0:42:42.00
GET-LATEST-SIGNALS-MIB::oversightInteger.4.0 = Wrong Type (should 
be OCTET STRING): IpAddress: 127.0.0.1
GET-LATEST-SIGNALS-MIB::oversightInteger.5.0 = Wrong Type (should  
e OCTET STRING): Counter32: 42
GET-LATEST-SIGNALS-MIB::oversightInteger.6.0 = Wrong Type (should 
be OCTET STRING): Gauge32: 42

So now I wanted to change the value”Life, the Universe, and Everything” dynamically so how we can change the oid values dynamically?.

I’m stuck at this point for almost 2 weeks now so any help will be really appreciated!!

Advertisement

Answer

So to solve this issue I have included a sqlite3 database.

Now, whenever we will get the latest values in our embedded c application (which will be always running behind) we are updating the same in the database so in between if SNMPD daemon receives any request for example set, get etc then the script will go and read the database to get the latest values of the mib varialbes and will be sent to the mib browser.

We are using the following command in the script to get the data from the database

echo "$(sqlite3 /home/root/database/pdu.db <<'END_SQL'
.timeout 2000
SELECT Variable_Value FROM Data Where Sr_No='2';
END_SQL)
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement