librenms/addhost.php
Tom Laermans a10d3f75ea syntaxer run
git-svn-id: http://www.observium.org/svn/observer/trunk@3008 61d68cd4-352d-0410-923a-c4978735b2b8
2012-04-09 15:30:45 +00:00

82 lines
1.6 KiB
PHP
Executable File

#!/usr/bin/env php
<?php
/* Observium Network Management and Monitoring System
* Copyright (C) 2006-2011, Observium Developers - http://www.observium.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* See COPYING for more details.
*/
chdir(dirname($argv[0]));
include("includes/defaults.inc.php");
include("config.php");
include("includes/functions.php");
if (isset($argv[1]) && $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 (@!$argv[5])
{
$transport = 'udp';
}
else
{
$transport = $argv[5];
}
if ($community)
{
$config['snmp']['community'] = array($community);
}
if ($snmpver)
{
$snmpversions[] = $snmpver;
}
else
{
$snmpversions = array('v2c','v1');
}
while (!$device_id && count($snmpversions))
{
$snmpver = array_shift($snmpversions);
$device_id = addHost($host, $snmpver, $port, $transport);
}
if ($device_id)
{
$device = device_by_id_cache($device_id);
echo("Added device ".$device['hostname']." (".$device_id.")\n");
}
} else {
print Console_Color::convert("
Observium v".$config['version']." Add Host Tool
Usage: ./addhost.php <%Whostname%n> [community] [v1|v2c] [port] [" . join("|",$config['snmp']['transports']) . "]
%rRemember to run discovery for the host afterwards.%n
");
}
?>