Ad Widget

Collapse

1.4.1 SNMP Discovery - Add hostname or reverse dns?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • whowd
    Junior Member
    • Jul 2007
    • 28

    #1

    1.4.1 SNMP Discovery - Add hostname or reverse dns?

    Is there anyway using SNMP discovery in Zabbix 1.4.1 to have Zabbix add the hostname to the created host? Currently it adds the host with just the IP address.

    Or is there an option or process to reverse dns lookup the IP to determine the DNS name?

    Thanks.
  • whowd
    Junior Member
    • Jul 2007
    • 28

    #2
    Didn't find anything on this subject, so I hacked up the following perl script and set it to run on the zabbix server.

    If you would like to use the script, fill in the database details and set $ip_start to the first few octets of your ip block.

    It will query for hosts with IPs as their name and then reverse dns and update with the host name.

    w

    Code:
    #!/usr/bin/perl
    #
    use DBI;
    use Socket;
    
    $ip_start = "10.10";
    
    $db_host = "localhost";
    $db_name = "zabbix";
    $db_user = "zabbix";
    $db_password = "password";
    
    $dbh = DBI->connect('dbi:mysql:database='.$db_name.';host=' . $db_host, $db_user, $db_password) or die $DBI::errstr;
    
    $sth = $dbh->prepare('SELECT hostid, host FROM hosts WHERE host LIKE ?')
                            or die("Could not prepare query for existing check");
    $sth->execute($ip_start . "%")
                            or die("Could not execute query to check existing rows");
    
    if($sth->rows > 0) {
            print "Found hosts with missing DNS names\n";
    } else {
            exit 1;
    }
    my( $id, $host);
    
    $sth->bind_columns(\$id, \$host);
    
    while($sth->fetch() ) {
            $name = gethostbyaddr(inet_aton($host), AF_INET);
            if(!$name) {
                    print "DNS failed for $host\n";
                    next;
            }
            $name = lc($name);
    
            $dbh->do("UPDATE hosts SET dns='$name' WHERE hostid = '$id'");
            $dbh->do("UPDATE hosts SET host='$name' WHERE hostid = '$id'");
    
            print "$id - $host - $name\n";
    }
    Last edited by whowd; 11-07-2007, 23:38.

    Comment

    • Alexei
      Founder, CEO
      Zabbix Certified Trainer
      Zabbix Certified SpecialistZabbix Certified Professional
      • Sep 2004
      • 5654

      #3
      This functionality is not supported by ZABBIX currently, but I'm looking forward implementing it soon.
      Alexei Vladishev
      Creator of Zabbix, Product manager
      New York | Tokyo | Riga
      My Twitter

      Comment

      Working...