2007-04-03 14:10:23 +00:00
|
|
|
#!/usr/bin/php
|
|
|
|
<?
|
2008-03-12 20:01:46 +00:00
|
|
|
|
2008-03-19 19:16:16 +00:00
|
|
|
include("config.php");
|
|
|
|
include("includes/functions.php");
|
2007-04-03 14:10:23 +00:00
|
|
|
|
|
|
|
if($argv[1] && $argv[2] && $argv[3]) {
|
|
|
|
$host = strtolower($argv[1]);
|
|
|
|
$community = $argv[2];
|
|
|
|
$snmpver = strtolower($argv[3]);
|
|
|
|
list($hostshort) = explode(".", $host);
|
|
|
|
if ( isDomainResolves($argv[1])){
|
|
|
|
if ( isPingable($argv[1])) {
|
2008-07-22 08:24:34 +00:00
|
|
|
if ( mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '".mres($host)."'"), 0) == '0' ) {
|
2007-04-03 14:10:23 +00:00
|
|
|
$snmphost = trim(`snmpget -Oqv -$snmpver -c $community $host sysName.0 | sed s/\"//g`);
|
|
|
|
if ($snmphost == $host || $hostshort = $host) {
|
2008-03-22 15:18:15 +00:00
|
|
|
$return = createHost ($host, $community, $snmpver);
|
|
|
|
if($return) { echo($return . "\n"); } else { echo("Adding $host failed\n"); }
|
2007-04-03 14:10:23 +00:00
|
|
|
} else { echo("Given hostname does not match SNMP-read hostname!\n"); }
|
|
|
|
} else { echo("Already got host $host\n"); }
|
|
|
|
} else { echo("Could not ping $host\n"); }
|
|
|
|
} else { echo("Could not resolve $host\n"); }
|
2008-03-22 15:03:55 +00:00
|
|
|
} else { echo("Add Host Tool\nUsage: ./addhost.php <hostname> <community> <snmpversion>\n"); }
|
2007-04-03 14:10:23 +00:00
|
|
|
|
|
|
|
?>
|