2007-04-03 14:10:23 +00:00
|
|
|
#!/usr/bin/php
|
2009-09-07 11:07:59 +00:00
|
|
|
<?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
|
|
|
|
2010-01-26 11:47:45 +00:00
|
|
|
if($argv[1]) {
|
2007-04-03 14:10:23 +00:00
|
|
|
$host = strtolower($argv[1]);
|
|
|
|
$community = $argv[2];
|
|
|
|
$snmpver = strtolower($argv[3]);
|
2009-02-02 16:00:11 +00:00
|
|
|
if (is_numeric($argv[4]))
|
|
|
|
$port = $argv[4];
|
|
|
|
else
|
|
|
|
$port = 161;
|
|
|
|
|
2010-01-26 11:47:45 +00:00
|
|
|
if (!$snmpver) $snmpver = "v2c";
|
|
|
|
if (!$community) $community = $config['community'];
|
|
|
|
|
2007-04-03 14:10:23 +00:00
|
|
|
list($hostshort) = explode(".", $host);
|
|
|
|
if ( isDomainResolves($argv[1])){
|
2009-04-28 11:23:38 +00:00
|
|
|
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' ) {
|
2009-04-28 11:23:38 +00:00
|
|
|
$snmphost = trim(str_replace("\"", "", shell_exec($config['snmpget'] ." -m SNMPv2-MIB -Oqv -$snmpver -c $community $host:$port sysName.0")));
|
2010-02-20 17:22:22 +00:00
|
|
|
if ($snmphost && ($snmphost == $host || $hostshort = $host)) {
|
2009-02-02 16:00:11 +00:00
|
|
|
$return = createHost ($host, $community, $snmpver, $port);
|
2008-03-22 15:18:15 +00:00
|
|
|
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"); }
|
2010-01-26 11:47:45 +00:00
|
|
|
} else { echo("Add Host Tool\nUsage: ./addhost.php <hostname> [community] [v1|v2c] [port]\n"); }
|
2007-04-03 14:10:23 +00:00
|
|
|
|
|
|
|
?>
|