2010-09-03 18:26:59 +00:00
|
|
|
#!/usr/bin/env php
|
2009-09-07 11:07:59 +00:00
|
|
|
<?php
|
2008-03-12 20:01:46 +00:00
|
|
|
|
2011-09-08 12:24:18 +00:00
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
|
2010-02-27 14:44:38 +00:00
|
|
|
include("includes/defaults.inc.php");
|
2011-03-16 09:29:46 +00:00
|
|
|
include("config.php");
|
2008-03-19 19:16:16 +00:00
|
|
|
include("includes/functions.php");
|
2007-04-03 14:10:23 +00:00
|
|
|
|
2011-03-14 18:53:48 +00:00
|
|
|
if (isset($argv[1]) && $argv[1])
|
2011-03-16 09:29:46 +00:00
|
|
|
{
|
2011-10-04 15:05:27 +00:00
|
|
|
$host = strtolower($argv[1]);
|
2011-03-23 09:54:56 +00:00
|
|
|
$community = $argv[2];
|
|
|
|
$snmpver = strtolower($argv[3]);
|
2011-03-14 18:56:26 +00:00
|
|
|
|
2011-03-23 09:54:56 +00:00
|
|
|
if (is_numeric($argv[4]))
|
|
|
|
{
|
|
|
|
$port = $argv[4];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$port = 161;
|
|
|
|
}
|
2009-02-02 16:00:11 +00:00
|
|
|
|
2011-03-23 09:54:56 +00:00
|
|
|
if (@!$argv[5])
|
|
|
|
{
|
|
|
|
$transport = 'udp';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$transport = $argv[5];
|
|
|
|
}
|
2011-03-15 16:12:44 +00:00
|
|
|
|
2011-03-23 09:54:56 +00:00
|
|
|
if (!$snmpver) $snmpver = "v2c";
|
|
|
|
if ($community)
|
|
|
|
{
|
2011-10-05 08:53:44 +00:00
|
|
|
$config['snmp']['community'] = array($community);
|
2011-03-23 09:54:56 +00:00
|
|
|
}
|
2011-10-04 15:05:27 +00:00
|
|
|
|
|
|
|
$device_id = addHost($host, $community, $snmpver, $port, $transport);
|
2011-03-15 16:12:44 +00:00
|
|
|
|
2011-09-20 15:48:12 +00:00
|
|
|
if ($device_id)
|
|
|
|
{
|
2011-09-14 17:26:59 +00:00
|
|
|
$device = device_by_id_cache($device_id);
|
2011-10-04 15:05:27 +00:00
|
|
|
echo("Added device ".$device['hostname']." (".$device_id.")\n");
|
2011-09-14 17:26:59 +00:00
|
|
|
}
|
2011-09-20 09:55:11 +00:00
|
|
|
} else {
|
2011-09-20 15:48:12 +00:00
|
|
|
print Console_Color::convert("
|
2011-09-08 12:24:18 +00:00
|
|
|
Observium v".$config['version']." Add Host Tool
|
2011-03-22 20:27:39 +00:00
|
|
|
|
2011-09-08 12:24:18 +00:00
|
|
|
Usage: ./addhost.php <%Whostname%n> [community] [v1|v2c] [port] [" . join("|",$config['snmp']['transports']) . "]
|
2011-03-22 20:27:39 +00:00
|
|
|
|
2011-09-20 15:48:12 +00:00
|
|
|
%rRemember to run discovery for the host afterwards.%n
|
2011-03-16 14:23:38 +00:00
|
|
|
|
2011-09-08 12:24:18 +00:00
|
|
|
");
|
|
|
|
}
|
2007-04-03 14:10:23 +00:00
|
|
|
|
2011-05-13 11:42:26 +00:00
|
|
|
?>
|