Ejemplo n.º 1
0
 function fetch_replacement($field, $item)
 {
     switch ($this->feedtype) {
         case 'atom':
             $handled_value = null;
             ($hook = vBulletinHook::fetch_hook('rssposter_parse_atom')) ? eval($hook) : false;
             if ($handled_value !== null) {
                 return $handled_value;
             }
             switch ($field) {
                 case 'link':
                     if (empty($item['link'])) {
                         if (!empty($item['guid'])) {
                             return $item['guid']['value'];
                         }
                         return '';
                     } else {
                         if (empty($item['link'][0])) {
                             return $item['link']['href'];
                         } else {
                             foreach ($item['link'] as $link) {
                                 if ($link['rel'] == 'alternate' or empty($link['rel'])) {
                                     return $link['href'];
                                 }
                             }
                         }
                     }
                     break;
                 case 'description':
                     return get_item_value($item['summary']);
                     break;
                 case 'title':
                     return get_item_value($item['title']);
                     break;
                 case 'id':
                     return get_item_value($item['id']);
                     break;
                 case 'date':
                     $timestamp = strtotime(get_item_value($item['updated']));
                     if ($timestamp > 0) {
                         return vbdate($this->registry->options['dateformat'] . " " . $this->registry->options['timeformat'], $timestamp);
                     } else {
                         return get_item_value($item['updated']);
                     }
                     break;
                 case 'enclosure_link':
                     if (empty($item['link'][0])) {
                         return '';
                     } else {
                         foreach ($item['link'] as $link) {
                             if ($link['rel'] == 'enclosure') {
                                 return $link['href'];
                             }
                         }
                     }
                     break;
                 case 'content':
                 case 'content:encoded':
                     if (empty($item['content'][0])) {
                         return get_item_value($item['content']);
                     } else {
                         $return = array();
                         foreach ($item['content'] as $contents) {
                             if (is_array($contents)) {
                                 if ($contents['type'] == 'html' and !($return['type'] == 'xhtml')) {
                                     $return = $contents;
                                 } elseif ($contents['type'] == 'text' and !($return['type'] == 'html' or $return['type'] == 'xhtml')) {
                                     $return = $contents;
                                 } elseif ($contents['type'] == 'xhtml') {
                                     $return = $contents;
                                 } elseif ($contents['type'] != 'xhtml' or $contents['type'] != 'xhtml' or $contents['type'] != 'xhtml') {
                                     $return = $contents;
                                 }
                             } else {
                                 if (empty($return['type'])) {
                                     $return['value'] = $contents;
                                 }
                             }
                         }
                         return $return['value'];
                     }
                     break;
                 case 'author':
                     return get_item_value($item['author']['name']);
                     break;
                 default:
                     if (is_array($item["{$field}"])) {
                         if (is_string($item["{$field}"]['value'])) {
                             return $item["{$field}"]['value'];
                         } else {
                             return '';
                         }
                     } else {
                         return $item["{$field}"];
                     }
             }
         case 'rss':
             $handled_value = null;
             ($hook = vBulletinHook::fetch_hook('rssposter_parse_rss')) ? eval($hook) : false;
             if ($handled_value !== null) {
                 return $handled_value;
             }
             switch ($field) {
                 case 'link':
                     if (empty($item['link'])) {
                         if (!empty($item['guid'])) {
                             return $item['guid']['value'];
                         }
                         return '';
                     } else {
                         if (is_array($item['link']) and isset($item['link']['href'])) {
                             return $item['link']['href'];
                         } else {
                             return get_item_value($item['link']);
                         }
                     }
                     break;
                 case 'description':
                     // this can be handled by the default case
                     return get_item_value($item['description']);
                     break;
                 case 'title':
                     // this can be handled by the default case
                     return get_item_value($item['title']);
                     break;
                 case 'id':
                 case 'guid':
                     return get_item_value($item['guid']);
                     break;
                 case 'pubDate':
                 case 'date':
                     $timestamp = strtotime(get_item_value($item['pubDate']));
                     if ($timestamp > 0) {
                         return vbdate($this->registry->options['dateformat'] . " " . $this->registry->options['timeformat'], $timestamp);
                     } else {
                         return $item['pubDate'];
                     }
                     break;
                 case 'enclosure_link':
                 case 'enclosure_href':
                     if (is_array($item['enclosure'])) {
                         return $item['enclosure']['url'];
                     } else {
                         return '';
                     }
                     break;
                 case 'content':
                 case 'content:encoded':
                     return get_item_value($item['content:encoded']);
                     break;
                 case 'author':
                 case 'dc:creator':
                     if (isset($item['dc:creator'])) {
                         return get_item_value($item['dc:creator']);
                     } else {
                         return $item['author'];
                     }
                     break;
                 default:
                     if (is_array($item["{$field}"])) {
                         if (is_string($item["{$field}"]['value'])) {
                             return $item["{$field}"]['value'];
                         } else {
                             return '';
                         }
                     } else {
                         return $item["{$field}"];
                     }
             }
     }
 }
Ejemplo n.º 2
0
function make_ipmistat_summary($preloading = false)
{
    $form_name = 'ipmi_control';
    $table = new CTableInfo();
    $ipmicontrol_form = new CForm();
    $ipmicontrol_form->setName('ipmi_control');
    $ipmicontrol_form->setAttribute('id', 'ipmi_control');
    $ipmicontrol_form->addVar('driver', 'ipmi');
    $script_itemkey = 'push_message.py[{$HYCLOPS_SERVER},{$HYCLOPS_PORT},ipmi,{HOST.HOST}]';
    $table->setHeader(array(is_show_all_nodes() ? S_NODE : null, new CCheckBox('all_physical_hosts', null, "checkAllHosts('" . $ipmicontrol_form->getName() . "', 'all_physical_hosts', '');"), _('Host name'), _('IPMI interface'), _('Status'), _('Problems')));
    $hosts = get_ipmi_hosts();
    if (empty($hosts)) {
        return null;
    }
    foreach ($hosts as $host) {
        $triggers = get_triggers($host['hostid']);
        $trigger_count = count($triggers);
        // get State
        if (!$preloading) {
            if (is_script_success($host['hostid'], $script_itemkey)) {
                $state = strtolower(get_item_value($host['hostid'], "ipmi.state.text"));
            } else {
                $state = _('script failed');
            }
        } else {
            $state = _('loading...');
        }
        // Check box
        $checkbox_col = new CCheckBox("hostids[]", null, null, $host['hostid']);
        if (!is_operation_available("ipmi", $state)) {
            $checkbox_col->attributes['disabled'] = 'disabled';
        }
        // Host name
        if ($trigger_count == 0) {
            $hostname_col = new CCol(new CSpan($host['host']));
        } else {
            $hostname_col = new CLink(new CSpan($host['host']), 'tr_status.php?&hostid=' . $host['hostid'] . '&show_triggers=' . TRIGGERS_OPTION_ONLYTRUE);
        }
        // IPMI Interfaces
        $ipmi_addresses = get_addresses($host['hostid'], INTERFACE_TYPE_IPMI);
        $ipmi_ip_col = new CCol(reset($ipmi_addresses));
        // Status
        $state_col = new CCol($state, get_item_level($state));
        // Problem
        if ($trigger_count == 0) {
            $problem_col = new CCol($trigger_count, 'normal');
        } else {
            $problem_col = new CCol($trigger_count, 'high');
            $problem_col->setHint(make_trigger_table($triggers, $hostname_col));
        }
        $r = new CRow();
        $r->addItem($checkbox_col);
        $r->addItem($hostname_col);
        $r->addItem($ipmi_ip_col);
        $r->addItem($state_col);
        $r->addItem($problem_col);
        $table->addRow($r);
    }
    $table->setFooter(new CCol(make_operation_box_footer(zbx_objectValues($hosts, 'hostid'), $form_name)));
    $ipmicontrol_form->addItem($table);
    $script = new CJSScript(get_js("jQuery('#hat_ipmistat_footer').html('" . _s('Updated: %s', zbx_date2str(_('H:i:s'))) . "')"));
    return new CDiv(array($ipmicontrol_form, $script));
}
Ejemplo n.º 3
0
             }
         }
     }
 }
 foreach ($feed['xml']->fetch_items() as $item) {
     // attach the rssfeedid to each item
     $item['rssfeedid'] = $rssfeedid;
     if (!empty($item['summary'])) {
         // ATOM
         $description = get_item_value($item['summary']);
     } elseif (!empty($item['content:encoded'])) {
         $description = get_item_value($item['content:encoded']);
     } elseif (!empty($item['content'])) {
         $description = get_item_value($item['content']);
     } else {
         $description = get_item_value($item['description']);
     }
     // backward compatability to RSS
     if (!isset($item['description'])) {
         $item['description'] = $description;
     }
     if (!isset($item['guid']) and isset($item['id'])) {
         $item['guid'] =& $item['id'];
     }
     if (!isset($item['pubDate'])) {
         if (isset($item['published'])) {
             $item['pubDate'] =& $item['published'];
         } elseif (isset($item['updated'])) {
             $item['pubDate'] =& $item['updated'];
         }
     }
Ejemplo n.º 4
0
function get_instances($owner_hostid, $sortfield = "name", $sortorder = "ASC")
{
    $NOT_EXIST_HOSTGROUP_NAME = "Not exist hosts";
    $owner_host = get_owner($owner_hostid);
    $all_hosts = API::Host()->get(array("output" => "extend", "selectInventory" => "extend", "selectInterfaces" => "extend", "selectScreens" => "extend", "selectGroups" => "extend"));
    $instances = array();
    foreach ($all_hosts as $host) {
        foreach ($host["groups"] as $group) {
            if ($group["name"] == $NOT_EXIST_HOSTGROUP_NAME) {
                continue 2;
            }
        }
        if (!isset($host["inventory"]["tag"])) {
            continue;
        }
        if ($owner_host["host"] == $host["inventory"]["tag"]) {
            $name = get_inventory_value($host["hostid"], "name");
            if (empty($name)) {
                $name = empty($host["name"]) ? $host["host"] : $host["name"];
            }
            $instance = array("host" => $host, "hostid" => $host["hostid"], "owner_hostid" => $owner_host["hostid"], "name" => $name, "state" => libcloud_state_mapping(get_item_value($host["hostid"], "instance.state")), "instance_id" => $host["host"], "instance_name" => get_inventory_value($host["hostid"], "name"), "type" => get_item_value($host["hostid"], "instance.type"), "realm_id" => get_item_value($host["hostid"], "instance.availability_zone"), "keyname" => get_item_value($host["hostid"], "instance.keyname"), "firewalls" => get_item_value($host["hostid"], "instance.security_groups"), "public_dns" => get_main_address($host["hostid"], INTERFACE_TYPE_AGENT), "ami_id" => get_item_value($host["hostid"], "instance.ami_id"), "private_dns" => get_item_value($host["hostid"], "instance.private_dns"), "elastic_ips" => get_item_value($host["hostid"], "instance.elastic_ips"), "private_ips" => get_item_value($host["hostid"], "instance.private_ips"), "launch_time" => get_item_value($host["hostid"], "instance.launch_time"), "ramdisk_id" => get_item_value($host["hostid"], "instance.ramdisk_id"), "kernel_id" => get_item_value($host["hostid"], "instance.kernel_id"), "platform" => get_item_value($host["hostid"], "instance.platform"), "ami_name" => get_item_value($host["hostid"], "instance.ami_name"), "cpu" => get_item_value($host["hostid"], "instance.cpu"), "memory" => get_item_value($host["hostid"], "instance.memory"), "stuck_state" => intval(get_item_value($host["hostid"], "instance.stuck.state")), "stuck_question" => get_item_value($host["hostid"], "instance.stuck.question"), "stuck_choices" => get_item_value($host["hostid"], "instance.stuck.choices"), "main_interface" => get_main_address($host["hostid"], INTERFACE_TYPE_AGENT));
            if (!empty($instance["memory"]) && (int) $instance["memory"] != 0) {
                $instance["memory"] = $instance["memory"] / pow(1024, 3);
            }
            array_push($instances, $instance);
        }
    }
    sort_data_array($instances, $sortfield, $sortorder);
    return $instances;
}