Welcome, Guest. Please login or register.

Author Topic: search-script for new devices  (Read 1699 times)

SteffenS

  • Guest
search-script for new devices
« on: August 18, 2010, 03:51:20 PM »
Hello all!
I have wrote a little script for detect new installed devices in specific subnets.
This safe me a lot of time.

If you want it, do this:

- append this 2 lines in /var/www/htdocs/System-Files.php after line 14 ("$files = array(            # Edit to fit your system...")
Code: [Select]
"new found Switches"=>"/var/nedi/new-found-switches.txt",
"ignored found Switches"=>"/var/nedi/new-switches-ignore.txt",

- create an empty file /var/nedi/new-switches-ignore.txt
- create an executable file /var/nedi/search-new-devices.sh with following content:
Code: [Select]
#!/bin/ksh
date>/var/nedi/new-found-switches.txt
for i in {64,65,66,67,68,69,70,71,72,74,75,76,77} #i=2.Oktett
do
j=0
while ((j<=254)) #j=3.Oktett
do
for k in {19,18,17,16,15,14,13,12,11,10} #k=4.Oktett
do
l=$(ping -c 1 -w 1 10.$i.$j.$k|wc -l ) #2=not reachable,5=reachable
if [ $l -eq 5 ];# if reachable Switch found
then
echo Switch reachable 10.$i.$j.$k
m=$(echo "select ip from devices where ip regexp $((10*16777216+$i*65536+$j*256+$k));"|mysql -u nedi --password=dbpa55 nedi|wc -l)
if [ $m -ne 2 ] # and if Switch-IP not in Database
then
echo new Switch found 10.$i.$j.$k
n=$(grep 10.$i.$j.$k /var/nedi/new-switches-ignore.txt|wc -l)
if [ $n -eq 0 ];# and if found IP not in ignore-list
then
echo 10.$i.$j.$k>>/var/nedi/new-found-switches.txt #write IP in file new-found-switches.txt
fi
fi
done
((j++))
done
done
date>>new-found-switches.txt
(In this sample, the script search in sub-nets 10.64.x.x-10.72.x.x and 10.74.x.x-10.77.x.x at end-IP .19-.10. Change it for your own wish.)

- add /var/nedi/search-new-devices.sh to your cron - or use it manualy
- in the file /var/nedi/new-found-switches.txt you can see all devices that was found, but are not in the nedi-database, so you can check this devices (snmp-settings) and add it to nedi
- if devices was found that not support snmp or should not managed, copy the ip in the file /var/nedi/new-switches-ignore.txt (sample-line: "<IP>=<name>=<comment>") and at the next run it will be ignored

Have a lot of Fun!
« Last Edit: August 18, 2010, 04:17:03 PM by SteffenS »