"Fossies" - the Fresh Open Source Software Archive

Member "pandora_server/util/snmptrap_gen.sh" (11 May 2023, 1228 Bytes) of package /linux/misc/pandorafms_server-7.0NG.771.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/bash
    2 
    3 # (c) Sancho Lerena 2014
    4 # This is an script to generate random SNMP traps. Should be used to 
    5 # test SNMP trap processing performance on Pandora FMS Server.
    6 # Licensed under BSD licence, do with it whatever you want :-)
    7 
    8 TRAPS=$1
    9 TARGET=$2
   10 OIDBASE="1.3.6.1.4.1"
   11 SOURCE=$3
   12 
   13 if [ $# -lt 2 ]
   14 then
   15     echo " "
   16     echo "Syntax error: "
   17     echo "SNMP Trap generator use: ./snmptrap_gen.sh <# No traps> <target ip> [<source_ip>]"
   18     echo "If <source_ip> is not provided, it will forge fake IP's"
   19     echo " "
   20     exit -1
   21 fi
   22 
   23 COUNTER=0
   24 
   25 while [ $COUNTER -lt $TRAPS ]
   26 do
   27 
   28     RAND=`date +%N`
   29     SMALLRAND=`date +%N|cut -c 2-5`
   30     FAKEOID=""
   31     if [ "$SOURCE" == "" ]
   32     then
   33         FAKEIP=`date +%N | cut -c 2-3`.`date +%N | cut -c 2-3`.`date +%N | cut -c 2-3`.`date +%N | cut -c 2-3`
   34     else
   35         FAKEIP=$SOURCE
   36     fi
   37 
   38     # Create a fake OID with random data using Enterprise base OID
   39     for (( i=0; i<${#RAND}; i++ )); do
   40         FAKEOID=${RAND:$i:1}.$FAKEOID
   41     done
   42 
   43     FAKEOID=$OIDBASE.$FAKEOID"1"
   44 
   45     # Send the fake TRAP
   46     snmptrap -v 1 -c public $TARGET $FAKEOID $FAKEIP 6 $SMALLRAND $RAND $FAKEOID".$COUNTER" i $SMALLRAND
   47     echo "snmptrap -v 1 -c public $TARGET $FAKEOID $FAKEIP 6 $SMALLRAND $RAND $FAKEOID.$COUNTER i $SMALLRAND"
   48 
   49     COUNTER=`expr $COUNTER + 1`
   50 
   51 done