/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage functions
 * @author     Adam Armstrong <*****@*****.**>
 * @copyright  (C) 2006-2014 Adam Armstrong
 *
 */
function get_entity_by_id_cache($type, $id)
{
    global $cache;
    if ($type !== 'port') {
        list($entity_table, $entity_id_field, $entity_name_field) = entity_type_translate($type);
    }
    if (is_array($cache[$type][$id])) {
        return $cache[$type][$id];
    } else {
        switch ($type) {
            case "port":
                $entity = get_port_by_id($id);
                break;
            default:
                $entity = dbFetchRow("SELECT * FROM `" . $entity_table . "` WHERE `" . $entity_id_field . "` = ?", array($id));
                if (function_exists('humanize_' . $type)) {
                    $do = 'humanize_' . $type;
                    $do($entity);
                }
                break;
        }
        if (is_array($entity)) {
            entity_rewrite($type, $entity);
            $cache[$type][$id] = $entity;
            return $entity;
        }
    }
    return FALSE;
}
Esempio n. 2
0
function generate_entity_popup_header($entity, $vars)
{
    $translate = entity_type_translate_array($vars['entity_type']);
    $vars['popup'] = TRUE;
    $vars['entity_icon'] = TRUE;
    switch ($vars['entity_type']) {
        case "sensor":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_sensor_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "toner":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_toner_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "bgp_peer":
            if ($entity['peer_device_id']) {
                $peer_dev = device_by_id_cache($entity['peer_device_id']);
                $peer_name = '<br /><a class="entity" style="font-weight: bold;">' . $peer_dev['hostname'] . '</a>';
            } else {
                if ($entity['reverse_dns']) {
                    $peer_name = '<br /><span style="font-weight: bold;">' . $entity['reverse_dns'] . '</span>';
                }
            }
            $astext = '<span>AS' . $entity['bgpPeerRemoteAs'];
            if ($entity['astext']) {
                $astext .= '<br />' . $entity['astext'] . '</span>';
            }
            $astext .= '</span>';
            $contents .= generate_box_open();
            $contents .= '
      <table class="' . OBS_CLASS_TABLE . '">
        <tr class="' . $entity['row_class'] . ' vertical-align" style="font-size: 10pt;">
          <td class="state-marker"></td>
          <td style="width: 10px;"></td>
          <td style="width: 10px;"><i class="' . $translate['icon'] . '"></i></td>
          <td><a class="entity-popup" style="font-size: 15px; font-weight: bold;">' . $entity['entity_shortname'] . '</a>' . $peer_name . '</td>
          <td class="text-nowrap" style="width: 20%;">' . $astext . '</td>
          <td></td>
        </tr>
      </table>';
            $contents .= generate_box_close();
            break;
        case "sla":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_sla_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "processor":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_processor_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "mempool":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_mempool_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "p2pradio":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_p2pradio_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "status":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_status_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "storage":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_storage_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "netscalervsvr":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_netscalervsvr_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "netscalersvc":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_netscalersvc_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "netscalersvcgrpmem":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_netscalersvcmem_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        default:
            entity_rewrite($vars['entity_type'], $entity);
            $contents = generate_box_open() . '
      <table class="' . OBS_CLASS_TABLE_STRIPED . '">
        <tr class="' . $entity['row_class'] . '" style="font-size: 10pt;">
          <td class="state-marker"></td>
          <td style="width: 10px;"></td>
          <td width="400"><i class="' . $translate['icon'] . '" style="margin-right: 10px;"></i> <a class="entity-popup" style="font-size: 15px; font-weight: bold;">' . $entity['entity_name'] . '</a></td>
          <td width="100"></td>
          <td></td>
        </tr>
      </table>' . generate_box_close();
    }
    return $contents;
}
Esempio n. 3
0
function generate_entity_link($entity_type, $entity, $text = NULL, $graph_type = NULL, $escape = TRUE, $short = FALSE)
{
    if (is_numeric($entity)) {
        $entity = get_entity_by_id_cache($entity_type, $entity);
    }
    entity_rewrite($entity_type, $entity);
    switch ($entity_type) {
        case "device":
            $link = generate_device_link($entity);
            break;
        case "mempool":
            $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'health', 'metric' => 'mempool'));
            break;
        case "processor":
            $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'health', 'metric' => 'processor'));
            break;
        case "status":
            $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'health', 'metric' => 'status', 'id' => $entity['status_id']));
            break;
        case "sensor":
            $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'health', 'metric' => $entity['sensor_class'], 'id' => $entity['sensor_id']));
            break;
        case "printersupply":
            $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'printing', 'supply' => $entity['supply_type']));
            break;
        case "port":
            $link = generate_port_link($entity, NULL, $graph_type, $escape, $short);
            break;
        case "storage":
            $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'health', 'metric' => 'storage'));
            break;
        case "bgp_peer":
            $url = generate_url(array('page' => 'device', 'device' => $entity['peer_device_id'] ? $entity['peer_device_id'] : $entity['device_id'], 'tab' => 'routing', 'proto' => 'bgp'));
            break;
        case "netscalervsvr":
            $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'loadbalancer', 'type' => 'netscaler_vsvr', 'vsvr' => $entity['vsvr_id']));
            break;
        case "netscalersvc":
            $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'loadbalancer', 'type' => 'netscaler_services', 'svc' => $entity['svc_id']));
            break;
        case "netscalersvcgrpmem":
            $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'loadbalancer', 'type' => 'netscaler_servicegroupmembers', 'svc' => $entity['svc_id']));
            break;
        case "sla":
            $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'slas', 'id' => $entity['sla_id']));
            break;
        case "pseudowire":
            $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'pseudowires', 'id' => $entity['pseudowire_id']));
            break;
        case "maintenance":
            $url = generate_url(array('page' => 'alert_maintenance', 'maintenance' => $entity['maint_id']));
            break;
        case "group":
            $url = generate_url(array('page' => 'group', 'group_id' => $entity['group_id']));
            break;
        case "virtualmachine":
            // If we know this device by its vm name in our system, create a link to it, else just print the name.
            if (get_device_id_by_hostname($entity['vm_name'])) {
                $link = generate_device_link(device_by_name($entity['vm_name']));
            } else {
                // Hardcode $link to just show the name, no actual link
                $link = $entity['vm_name'];
            }
            break;
        default:
            $url = NULL;
    }
    if (!isset($link)) {
        if (!isset($text)) {
            if ($short && $entity['entity_shortname']) {
                $text = $entity['entity_shortname'];
            } else {
                $text = $entity['entity_name'];
            }
        }
        if ($escape) {
            $text = escape_html($text);
        }
        $link = '<a href="' . $url . '" class="entity-popup ' . $entity['html_class'] . '" data-eid="' . $entity['entity_id'] . '" data-etype="' . $entity_type . '">' . $text . '</a>';
    }
    return $link;
}
function generate_entity_link($entity_type, $entity, $text = NULL, $graph_type = NULL, $escape = TRUE)
{
    global $config, $entity_cache;
    if (is_numeric($entity)) {
        $entity = get_entity_by_id_cache($entity_type, $entity);
    }
    entity_rewrite($entity_type, $entity);
    // Rewrite sensor subtypes to 'sensor'
    // $translate = entity_type_translate_array($type);
    // if (isset($translate['parent_type'])) { $type = $translate['parent_type']; }
    switch ($entity_type) {
        case "device":
            $link = generate_device_link($entity);
            break;
        case "mempool":
            $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'health', 'metric' => 'mempool'));
            break;
        case "processor":
            $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'health', 'metric' => 'processor'));
            break;
        case "status":
            $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'health', 'metric' => 'status'));
            break;
        case "sensor":
            $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'health', 'metric' => $entity['sensor_class']));
            break;
        case "toner":
            $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'printing'));
            break;
        case "port":
            $link = generate_port_link($entity, NULL, $graph_type, $escape);
            break;
        case "storage":
            $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'health', 'metric' => 'storage'));
            break;
        case "bgp_peer":
            $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'routing', 'proto' => 'bgp'));
            break;
        case "netscaler_vsvr":
            $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'loadbalancer', 'type' => 'netscaler_vsvr', 'vsvr' => $entity['vsvr_id']));
            break;
        case "netscaler_svc":
            $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'loadbalancer', 'type' => 'netscaler_services', 'svc' => $entity['svc_id']));
            break;
        case "sla":
            $url = generate_url(array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'slas'));
            break;
        default:
            $url = NULL;
    }
    if (!isset($link)) {
        if (!isset($text)) {
            $text = $entity['entity_name'];
        }
        if ($escape) {
            $text = escape_html($text);
        }
        $link = '<a href="' . $url . '" class="entity-popup ' . $entity['html_class'] . '" data-eid="' . $entity['entity_id'] . '" data-etype="' . $entity_type . '">' . $text . '</a>';
    }
    return $link;
}