mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
git-svn-id: http://www.observium.org/svn/observer/trunk@1446 61d68cd4-352d-0410-923a-c4978735b2b8
37 lines
1.5 KiB
PHP
Executable File
37 lines
1.5 KiB
PHP
Executable File
#!/usr/bin/php
|
|
<?php
|
|
|
|
include("includes/defaults.inc.php");
|
|
include("config.php");
|
|
include("includes/functions.php");
|
|
|
|
if($argv[1]) {
|
|
$host = strtolower($argv[1]);
|
|
$community = $argv[2];
|
|
$snmpver = strtolower($argv[3]);
|
|
if (is_numeric($argv[4]))
|
|
$port = $argv[4];
|
|
else
|
|
$port = 161;
|
|
|
|
if (!$snmpver) $snmpver = "v2c";
|
|
if (!$community) $community = $config['snmp']['community'][0];
|
|
|
|
list($hostshort) = explode(".", $host);
|
|
if ( mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '".mres($host)."'"), 0) == '0' ) {
|
|
if ( isDomainResolves($argv[1])){
|
|
if ( isPingable($argv[1])) {
|
|
if ( isSNMPable($argv[1], $community, $snmpver, $port)) {
|
|
$snmphost = trim(str_replace("\"", "", shell_exec($config['snmpget'] ." -m SNMPv2-MIB -Oqv -$snmpver -c $community $host:$port sysName.0")));
|
|
if ($snmphost == "" || ($snmphost && ($snmphost == $host || $hostshort = $host))) {
|
|
$return = createHost ($host, $community, $snmpver, $port);
|
|
if($return) { echo($return . "\n"); } else { echo("Adding $host failed\n"); }
|
|
} else { echo("Given hostname does not match SNMP-read hostname ($snmphost)!\n"); }
|
|
} else { echo("Could not reach $host with SNMP\n"); }
|
|
} else { echo("Could not ping $host\n"); }
|
|
} else { echo("Could not resolve $host\n"); }
|
|
} else { echo("Already got host $host\n"); }
|
|
} else { echo("Add Host Tool\nUsage: ./addhost.php <hostname> [community] [v1|v2c] [port]\n"); }
|
|
|
|
?>
|