Beispiel #1
0
function print_vm_row($vm, $device = NULL)
{
    echo '<tr>';
    echo '<td>';
    if (getidbyname($vm['vmwVmDisplayName'])) {
        echo generate_device_link(device_by_name($vm['vmwVmDisplayName']));
    } else {
        echo $vm['vmwVmDisplayName'];
    }
    echo "</td>";
    echo '<td>' . $vm['vmwVmState'] . "</td>";
    if ($vm['vmwVmGuestOS'] == "E: tools not installed") {
        echo '<td class="small">Unknown (VMware Tools not installed)</td>';
    } else {
        if ($vm['vmwVmGuestOS'] == "E: tools not running") {
            echo '<td class="small">Unknown (VMware Tools not running)</td>';
        } else {
            if ($vm['vmwVmGuestOS'] == "") {
                echo '<td class="small"><i>(Unknown)</i></td>';
            } elseif (isset($config['vmware_guestid'][$vm['vmwVmGuestOS']])) {
                echo '<td>' . $config['vmware_guestid'][$vm['vmwVmGuestOS']] . "</td>";
            } else {
                echo '<td>' . $vm['vmwVmGuestOS'] . "</td>";
            }
        }
    }
    if ($vm['vmwVmMemSize'] >= 1024) {
        echo "<td class=list>" . sprintf("%.2f", $vm['vmwVmMemSize'] / 1024) . " GB</td>";
    } else {
        echo "<td class=list>" . sprintf("%.2f", $vm['vmwVmMemSize']) . " MB</td>";
    }
    echo '<td>' . $vm['vmwVmCpus'] . " CPU</td>";
}
function get_inventory()
{
    global $config;
    $app = \Slim\Slim::getInstance();
    $router = $app->router()->getCurrentRoute()->getParams();
    $status = 'error';
    $err_msg = '';
    $code = 500;
    $hostname = $router['hostname'];
    // use hostname as device_id if it's all digits
    $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
    $sql = '';
    $params = array();
    if (isset($_GET['entPhysicalClass']) && !empty($_GET['entPhysicalClass'])) {
        $sql .= ' AND entPhysicalClass=?';
        $params[] = mres($_GET['entPhysicalClass']);
    }
    if (isset($_GET['entPhysicalContainedIn']) && !empty($_GET['entPhysicalContainedIn'])) {
        $sql .= ' AND entPhysicalContainedIn=?';
        $params[] = mres($_GET['entPhysicalContainedIn']);
    } else {
        $sql .= ' AND entPhysicalContainedIn="0"';
    }
    if (!is_numeric($device_id)) {
        $err_msg = 'Invalid device provided';
        $total_inv = 0;
        $inventory = array();
    } else {
        $inventory = dbFetchRows("SELECT * FROM `entPhysical` WHERE 1 {$sql}", $params);
        $code = 200;
        $status = 'ok';
        $total_inv = count($inventory);
    }
    $output = array('status' => $status, 'err-msg' => $err_msg, 'count' => $total_inv, 'inventory' => $inventory);
    $app->response->setStatus($code);
    $app->response->headers->set('Content-Type', 'application/json');
    echo _json_encode($output);
}
Beispiel #3
0
$pagetitle[] = 'Syslog';
print_optionbar_start();
?>


<div id="{{ctx.id}}" class="{{css.header}}">
    <div class="row">
        <div class="col-sm-9 actionBar">
            <div class="pull-left">
                <form method="post" action="" class="form-inline" role="form" id="result_form">
                    <div class="form-group">
                        <select name="device" id="device" class="form-control input-sm">
                            <option value="">All Devices</option>
                                <?php 
foreach (get_all_devices() as $hostname) {
    $device_id = getidbyname($hostname);
    if (device_permitted($device_id)) {
        echo '"<option value="' . $device_id . '"';
        if ($device_id == $vars['device']) {
            echo ' selected';
        }
        echo '>' . $hostname . '</option>';
    }
}
?>
                        </select>
                    </div>
                    <div class="form-group">
                        <select name="program" id="program" class="form-control input-sm">
                            <option value="">All Programs</option>
                                <?php 
Beispiel #4
0
<?php

echo '<tr class="list">';
echo '<td class="list">';
if (getidbyname($vm['vmwVmDisplayName'])) {
    echo generate_device_link(device_by_name($vm['vmwVmDisplayName']));
} else {
    echo $vm['vmwVmDisplayName'];
}
echo '</td>';
echo '<td class="list">' . $vm['vmwVmState'] . '</td>';
if ($vm['vmwVmGuestOS'] == 'E: tools not installed') {
    echo '<td class="box-desc">Unknown (VMware Tools not installed)</td>';
} else {
    if ($vm['vmwVmGuestOS'] == '') {
        echo '<td class="box-desc"><i>(Unknown)</i></td>';
    } else {
        if (isset($config['vmware_guestid'][$vm['vmwVmGuestOS']])) {
            echo '<td class="list">' . $config['vmware_guestid'][$vm['vmwVmGuestOS']] . '</td>';
        } else {
            echo '<td class="list">' . $vm['vmwVmGuestOS'] . '</td>';
        }
    }
}
if ($vm['vmwVmMemSize'] >= 1024) {
    echo '<td class=list>' . sprintf('%.2f', $vm['vmwVmMemSize'] / 1024) . ' GB</td>';
} else {
    echo '<td class=list>' . sprintf('%.2f', $vm['vmwVmMemSize']) . ' MB</td>';
}
echo '<td class="list">' . $vm['vmwVmCpus'] . ' CPU</td>';
Beispiel #5
0
function device_by_name($name, $refresh = 0)
{
    // FIXME - cache name > id too.
    return device_by_id_cache(getidbyname($name), $refresh);
}
Beispiel #6
0
function update_device()
{
    global $config;
    $app = \Slim\Slim::getInstance();
    $router = $app->router()->getCurrentRoute()->getParams();
    $status = 'error';
    $code = 500;
    $hostname = $router['hostname'];
    // use hostname as device_id if it's all digits
    $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
    $data = json_decode(file_get_contents('php://input'), true);
    $bad_fields = array('id', 'hostname');
    if (empty($data['field'])) {
        $message = 'Device field to patch has not been supplied';
    } elseif (in_array($data['field'], $bad_fields)) {
        $message = 'Device field is not allowed to be updated';
    } else {
        if (dbUpdate(array(mres($data['field']) => mres($data['data'])), 'devices', '`device_id`=?', array($device_id)) >= 0) {
            $status = 'ok';
            $message = 'Device ' . mres($data['field']) . ' field has been updated';
            $code = 200;
        } else {
            $message = 'Device ' . mres($data['field']) . ' field failed to be updated';
        }
    }
    $output = array('status' => $status, 'message' => $message);
    $app->response->setStatus($code);
    $app->response->headers->set('Content-Type', 'application/json');
    echo _json_encode($output);
}
Beispiel #7
0
function list_ipsec()
{
    $app = \Slim\Slim::getInstance();
    $router = $app->router()->getCurrentRoute()->getParams();
    $status = 'error';
    $code = 404;
    $message = '';
    $hostname = $router['hostname'];
    // use hostname as device_id if it's all digits
    $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
    if (!is_numeric($device_id)) {
        $message = "No valid hostname or device ID provided";
    } else {
        $ipsec = dbFetchRows("SELECT `D`.`hostname`, `I`.* FROM `ipsec_tunnels` AS `I`, `devices` AS `D` WHERE `I`.`device_id`=? AND `D`.`device_id` = `I`.`device_id`", array($device_id));
        $total = count($ipsec);
        $status = 'ok';
        $code = 200;
    }
    $output = array('status' => $status, 'err-msg' => $message, 'count' => $total, 'ipsec' => $ipsec);
    $app->response->setStatus($code);
    $app->response->headers->set('Content-Type', 'application/json');
    echo _json_encode($output);
}
Beispiel #8
0
function list_services()
{
    global $config;
    $app = \Slim\Slim::getInstance();
    $router = $app->router()->getCurrentRoute()->getParams();
    $status = 'ok';
    $code = 200;
    $message = '';
    $host_par = array();
    $sql_param = array();
    $services = array();
    $where = '';
    $devicewhere = '';
    // Filter BY STATE
    if (isset($_GET['state'])) {
        $where = " AND S.service_status= ? AND S.service_disabled='0' AND S.service_ignore='0'";
        $host_par[] = $_GET['state'];
        if (!is_numeric($_GET['state'])) {
            $status = 'error';
            $message = "No valid service state provided, valid option is 0=Ok, 1=Warning, 2=Critical";
        }
    }
    // GET BY HOST
    if (isset($router['hostname'])) {
        $hostname = $router['hostname'];
        $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
        $where .= " AND S.device_id = ?";
        $host_par[] = $device_id;
        if (!is_numeric($device_id)) {
            $status = 'error';
            $message = "No valid hostname or device id provided";
        }
    }
    // DEVICE
    $host_sql = 'SELECT * FROM devices AS D, services AS S WHERE D.device_id = S.device_id ' . $where . ' GROUP BY D.hostname ORDER BY D.hostname';
    // SERVICE
    foreach (dbFetchRows($host_sql, $host_par) as $device) {
        $device_id = $device['device_id'];
        $sql_param[0] = $device_id;
        // FILTER BY TYPE
        if (isset($_GET['type'])) {
            $devicewhere = " AND `service_type` LIKE ?";
            $sql_param[1] = $_GET['type'];
        }
        $services = dbFetchRows("SELECT * FROM `services` WHERE `device_id` = ?" . $devicewhere, $sql_param);
    }
    $count = count($services);
    $output = array('status' => $status, 'err-msg' => $message, 'count' => $count, 'services' => $services);
    $app->response->setStatus($code);
    $app->response->headers->set('Content-Type', 'application/json');
    echo _json_encode($output);
}
function get_port_graphs()
{
    global $config;
    $app = \Slim\Slim::getInstance();
    $router = $app->router()->getCurrentRoute()->getParams();
    $hostname = $router['hostname'];
    if (isset($_GET['columns'])) {
        $columns = $_GET['columns'];
    } else {
        $columns = 'ifName';
    }
    // use hostname as device_id if it's all digits
    $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
    $ports = dbFetchRows("SELECT {$columns} FROM `ports` WHERE `device_id` = ? AND `deleted` = '0' ORDER BY `ifIndex` ASC", array($device_id));
    $total_ports = count($ports);
    $output = array("status" => "ok", "err-msg" => '', "count" => $total_ports, "ports" => $ports);
    $app->response->setStatus('200');
    $app->response->headers->set('Content-Type', 'application/json');
    echo _json_encode($output);
}
Beispiel #10
0
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage cli
 * @author     Adam Armstrong <*****@*****.**>
 * @copyright  (C) 2006-2014 Adam Armstrong
 *
 */
chdir(dirname($argv[0]));
include "includes/defaults.inc.php";
include "config.php";
include "includes/definitions.inc.php";
include "includes/functions.inc.php";
$scriptname = basename($argv[0]);
print_message("%g" . OBSERVIUM_PRODUCT . " " . OBSERVIUM_VERSION . "\n%WRemove Device%n\n", 'color');
// Remove a host and all related data from the system
if ($argv[1]) {
    $host = strtolower($argv[1]);
    $id = getidbyname($host);
    $delete_rrd = isset($argv[2]) && strtolower($argv[2]) == 'rrd' ? TRUE : FALSE;
    // Test if a valid id was fetched from getidbyname.
    if (isset($id) && is_numeric($id)) {
        print_warning(delete_device($id, $delete_rrd));
        print_success("Device {$host} removed.");
    } else {
        print_error("Device {$host} doesn't exist!");
    }
} else {
    print_message("%n\nUSAGE:\n{$scriptname} <hostname> [rrd]\n\nEXAMPLE:\n%WKeep RRDs%n:   {$scriptname} <hostname>\n%WRemove RRDs%n: {$scriptname} <hostname> rrd\n\n%rInvalid arguments!%n", 'color', FALSE);
}
// EOF
Beispiel #11
0
    templates: {
        header: "<div id=\"{{ctx.id}}\" class=\"{{css.header}}\"><div class=\"row\">"+
                "<div class=\"col-sm-8 actionBar\"><span class=\"pull-left\">"+
                "<form method=\"post\" action=\"\" class=\"form-inline\" role=\"form\" id=\"result_form\">"+
                "<div class=\"form-group\">"+
                "<label>"+
                "<strong>Device&nbsp;</strong>"+
                "</label>"+
                "<select name=\"device_id\" id=\"device_id\" class=\"form-control input-sm\">"+
                "<option value=\"\">All Devices</option>"+
<?php 
foreach (get_all_devices() as $hostname) {
    $device_id = getidbyname($hostname);
    if (device_permitted($device_id)) {
        echo '"<option value=\\"' . $device_id . '\\""+';
        if (getidbyname($hostname) == $_POST['device_id']) {
            echo '" selected "+';
        }
        echo '">' . $hostname . '</option>"+';
    }
}
?>
               "</select>"+
               "</div>"+
               "<div class=\"form-group\">"+
               "<label>"+
               "<strong>&nbsp;State&nbsp;</strong>"+
               "</label>"+
               "<select name=\"state\" id=\"state\" class=\"form-control input-sm\">"+
               "<option value=\"-1\"></option>"+
               "<option value=\"0\">Ok</option>"+
Beispiel #12
0
 * @copyright  (C) 2006-2014 Adam Armstrong
 *
 */
chdir(dirname($argv[0]));
include "includes/defaults.inc.php";
include "config.php";
include "includes/definitions.inc.php";
include "includes/functions.inc.php";
$scriptname = basename($argv[0]);
print_message("%g" . OBSERVIUM_PRODUCT . " " . OBSERVIUM_VERSION . "\n%WRename Device%n\n", 'color');
// Remove a host and all related data from the system
if ($argv[1] && $argv[2]) {
    $host = strtolower($argv[1]);
    $id = getidbyname($host);
    if ($id) {
        $tohost = strtolower($argv[2]);
        $toid = getidbyname($tohost);
        if ($toid) {
            print_error("NOT renamed. New hostname {$tohost} already exists.");
        } else {
            if (renamehost($id, $tohost, 'console')) {
                print_message("Host {$host} renamed to {$tohost}.");
            }
        }
    } else {
        print_error("Host {$host} doesn't exist.");
    }
} else {
    print_message("%n\nUSAGE:\n{$scriptname} <old hostname> <new hostname>\n\n%rInvalid arguments!%n", 'color', FALSE);
}
// EOF
function get_device_groups()
{
    $app = \Slim\Slim::getInstance();
    $router = $app->router()->getCurrentRoute()->getParams();
    $status = 'error';
    $code = 404;
    $hostname = $router['hostname'];
    // use hostname as device_id if it's all digits
    $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
    if (is_numeric($device_id)) {
        $groups = GetGroupsFromDevice($device_id, 1);
    } else {
        $groups = GetDeviceGroups();
    }
    if (empty($groups)) {
        $message = 'No device groups found';
    } else {
        $status = 'ok';
        $code = 200;
        $message = 'Found ' . count($groups) . ' device groups';
    }
    $output = array('status' => $status, 'message' => $message, 'count' => count($groups), 'groups' => $groups);
    $app->response->setStatus($code);
    $app->response->headers->set('Content-Type', 'application/json');
    echo _json_encode($output);
}
Beispiel #14
0
    templates: {
        header: "<div id=\"{{ctx.id}}\" class=\"{{css.header}}\"><div class=\"row\">"+
                "<div class=\"col-sm-8 actionBar\"><span class=\"pull-left\">"+
                "<form method=\"post\" action=\"\" class=\"form-inline\" role=\"form\" id=\"result_form\">"+
                "<div class=\"form-group\">"+
                "<label>"+
                "<strong>Device&nbsp;</strong>"+
                "</label>"+
                "<select name=\"device_id\" id=\"device_id\" class=\"form-control input-sm\">"+
                "<option value=\"\">All Devices</option>"+
<?php 
foreach (get_all_devices() as $hostname) {
    $device_id = getidbyname($hostname);
    if (device_permitted($device_id)) {
        echo '"<option value=\\"' . $device_id . '\\""+';
        if (getidbyname($hostname) == $vars['device_id']) {
            echo '" selected "+';
        }
        echo '">' . $hostname . '</option>"+';
    }
}
?>
               "</select>"+
               "</div>"+
               "<button type=\"submit\" class=\"btn btn-default input-sm\">Filter</button>"+
               "</form></span></div>"+
               "<div class=\"col-sm-4 actionBar\"><p class=\"{{css.search}}\"></p><p class=\"{{css.actions}}\"></p></div></div></div>"
    },
    post: function ()
    {
        return {
Beispiel #15
0
function list_arp()
{
    $app = \Slim\Slim::getInstance();
    $router = $app->router()->getCurrentRoute()->getParams();
    $status = 'error';
    $code = 404;
    $message = '';
    $ip = $router['ip'];
    if (empty($ip)) {
        $message = "No valid IP provided";
    } else {
        $code = 200;
        $status = 'ok';
        if ($ip === "all") {
            $hostname = mres($_GET['device']);
            $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
            $arp = dbFetchRows("SELECT `ipv4_mac`.* FROM `ipv4_mac` LEFT JOIN `ports` ON `ipv4_mac`.`port_id` = `ports`.`port_id` WHERE `ports`.`device_id` = ?", array($device_id));
        } else {
            $arp = dbFetchRows("SELECT * FROM `ipv4_mac` WHERE `ipv4_address`=?", array($ip));
        }
        $total = count($arp);
    }
    $output = array('status' => $status, 'err-msg' => $message, 'count' => $total, 'arp' => $arp);
    $app->response->setStatus($code);
    $app->response->headers->set('Content-Type', 'application/json');
    echo _json_encode($output);
}
Beispiel #16
0
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage webui
 * @copyright  (C) 2006-2014 Adam Armstrong
 *
 */
// If we've been given a hostname, try to retrieve the device_id
if (isset($vars['device']) && !is_numeric($vars['device'])) {
    $vars['hostname'] = $vars['device'];
    unset($vars['device']);
}
if (empty($vars['device']) && !empty($vars['hostname'])) {
    $vars['device'] = getidbyname($vars['hostname']);
    // If device lookup fails, generate an error.
    if (empty($vars['device'])) {
        print_error('<h3>Invalid Hostname</h3>
                   A device matching the given hostname was not found. Please retype the hostname and try again.');
        break;
    }
}
// If there is no device specified in the URL, generate an error.
if (empty($vars['device'])) {
    print_error('<h3>No device specified</h3>
                   A valid device was not specified in the URL. Please retype and try again.');
    break;
}
// Allow people to see this page if they have permission to see one of the ports, but don't show them tabs.
$permit_ports = FALSE;