Cacti (home)ForumsRepositoryDocumentation
Cacti: offical forums and support  

 FAQFAQ   SearchSearch   MemberlistMemberlist    RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in    


mac-import from host table

 
Post new topic   Reply to topic    Cacti Forum Index -> Plugin: (MAC Track)
Author Message
torstentfk
Cacti User


Joined: 05 Apr 2005
Posts: 181
Location: Munich, Germany

PostPosted: Wed Feb 20, 2008 4:37 am    Post subject: mac-import from host table Reply with quote

Hi,
this scripts imports the devices from the host-db into the mac-device-db (see function usage() ).

Code:

#/bin/bash

# change path and insert here username and password for sql db
m=" /usr/bin/mysql -u cacti --password=cacti

 
usage () {
        echo "Usage: ./`basename $1` Site-Number [hostgrep] [--test]"
        echo "  Script imports devices from the cacti-host table to the mac-device-table"
        echo "  The Site-number is the ID used in mactrack-site -- List all sites with  --list asaramter"
        echo "  hostgrep is optional to select some specifc hosts"
        echo "  --test: do only testing; no sql insert"
     
}

if [ "$1" = "--list" ]; then
   echo "select site_id, site_name, site_info from mac_track_sites"| $m --table  cacti
  exit
fi
x=0
if  [ "$3" = "--test" ]; then
   x=1
   echo Doing only test.
fi


if [ $# -le 1 ]; then
  usage $0
  exit 1
fi


for line in `echo "select description, hostname, snmp_community,snmp_version,snmp_port,snmp_timeout from host;"| $m --skip-column-names  cacti | awk 'FS=" ";{print $1";"$2";"$3;};'|grep ";" | grep $2`
{
    #echo $line
    d=`echo $line | awk 'BEGIN {FS=";"} {print $1;};'  `
    h=`echo $line | awk 'BEGIN {FS=";"} {print $2;};'  `
    c=`echo $line | awk 'BEGIN {FS=";"} {print $3;};'  `
    sv=`echo $line | awk 'BEGIN {FS=";"} {print $4;};'  `
    sp=`echo $line | awk 'BEGIN {FS=";"} {print $5;};'  `
    st=`echo $line | awk 'BEGIN {FS=";"} {print $6;};'  `

    echo -n "Device:$d  Host-IP:$h   Comm:$c   --- "

    s=$1
    #hup=0; switch=1; Layer3=3
    r=1;
  t=`echo "select device_name from mac_track_devices where device_name='$d'"| $m  --skip-column-names  cacti`


if [ "$t" = "$d" ]; then
  echo Device already in mactrack-DB
else
  if [ "$x" = "1" ]; then
   echo "This device would be inserted "
  else
echo "INSERT INTO \`mac_track_devices\` ( \`site_id\` , \`device_id\` , \`device_name\` , \`device_type_id\` , \`hostname\` , \`notes\` , \`disabled\` , \`ignorePorts\` , \`ips_total\` , \`vlans_total\` , \`ports_total\` , \`ports_active\` , \`ports_trunk\` , \`macs_active\` , \`scan_type\` , \`user_name\` , \`user_password\` , \`snmp_readstring\` , \`snmp_readstrings\` , \`snmp_version\` , \`snmp_port\` , \`snmp_timeout\` , \`snmp_retries\` , \`snmp_sysName\` , \`snmp_sysLocation\` , \`snmp_sysContact\` , \`snmp_sysObjectID\` , \`snmp_sysDescr\` , \`snmp_sysUptime\` , \`snmp_status\` , \`last_runmessage\` , \`last_rundate\` , \`last_runduration\` ) VALUES ( '$s', NULL , '$d', '0', '$h', NULL , '', NULL , '0', '0', '0', '0', '0', '0', '$r', NULL , NULL , '$c', NULL , '$sv', '$sp', '$st', '3', '', '', '', NULL , NULL , NULL , '0', '', '0000-00-00 00:00:00', '0.00000' );" |$m  --skip-column-names  cacti
  echo inserted
 fi
fi

}


Torsten
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Cacti Forum Index -> Plugin: (MAC Track) All times are GMT - 5 Hours
Page 1 of 1

 



Powered by phpBB © 2001, 2005 phpBB Group