Exemplo n.º 1
0
function copy_template_applications($hostid, $templateid = null, $copy_mode = false)
{
    if (null == $templateid) {
        $templateid = array_keys(get_templates_by_hostid($hostid));
    }
    if (is_array($templateid)) {
        foreach ($templateid as $id) {
            copy_template_applications($hostid, $id, $copy_mode);
        }
        // attention recursion
        return;
    }
    $db_tmp_applications = get_applications_by_hostid($templateid);
    while ($db_tmp_app = DBfetch($db_tmp_applications)) {
        add_application($db_tmp_app['name'], $hostid, $copy_mode ? 0 : $db_tmp_app['applicationid']);
    }
}
Exemplo n.º 2
0
        if (make_app_version_dir($app_name, $i, $platform)) {
            error("Couldn't create dir: {$app_dir}");
        }
        $file = "{$app_dir}/{$app_name}" . "_1." . $i;
        if (!copy($wrapper_filename, $file)) {
            error("Couldn't copy {$wrapper_filename} to {$file}");
        }
        chmod($file, 0750);
        echo "- type 'bin/update_versions', and answer 'y' to all questions.\n";
    }
}
// make sure daemons are in the config file
//
function check_config_file()
{
    global $app_name, $platform;
    $config = file_get_contents('config.xml');
    if (!strstr($config, "single_job_assimilator")) {
        echo "- Add the following to the <daemons> section of config.xml:\n\n    <daemon>\n      <cmd>single_job_assimilator -app {$app_name}</cmd>\n      <output>single_job_assimilator_{$platform}.out</output>\n      <pid>single_job_assimilator_{$platform}.pid</pid>\n    </daemon>\n    <daemon>\n      <cmd>sample_trivial_validator -app {$app_name}</cmd>\n      <output>sample_trivial_validator_{$platform}.out</output>\n      <pid>sample_trivial_validator_{$platform}.pid</pid>\n    </daemon>\nThen restart your project by typing\nbin/stop\nbin/start\n    ";
    }
}
if ($argc != 2) {
    usage();
}
$boinc_samples_dir = $argv[1];
check_wrapper_exists();
get_includes();
add_application();
add_apps_dir();
create_app_dir();
check_config_file();
Exemplo n.º 3
0
        				'Old status ['.$host['status'].'] '.'New status ['.$status.']');*/
    }
    $result = DBend($result);
    show_messages($result, S_HOST_STATUS_UPDATED, S_CANNOT_UPDATE_HOST);
    unset($_REQUEST['activate']);
}
if ($_REQUEST['config'] == 4 && isset($_REQUEST['save'])) {
    DBstart();
    if (isset($_REQUEST['applicationid'])) {
        $result = update_application($_REQUEST['applicationid'], $_REQUEST['appname'], $_REQUEST['apphostid']);
        $action = AUDIT_ACTION_UPDATE;
        $msg_ok = S_APPLICATION_UPDATED;
        $msg_fail = S_CANNOT_UPDATE_APPLICATION;
        $applicationid = $_REQUEST['applicationid'];
    } else {
        $applicationid = add_application($_REQUEST['appname'], $_REQUEST['apphostid']);
        $action = AUDIT_ACTION_ADD;
        $msg_ok = S_APPLICATION_ADDED;
        $msg_fail = S_CANNOT_ADD_APPLICATION;
    }
    $result = DBend($applicationid);
    show_messages($result, $msg_ok, $msg_fail);
    if ($result) {
        add_audit($action, AUDIT_RESOURCE_APPLICATION, S_APPLICATION . ' [' . $_REQUEST['appname'] . ' ] [' . $applicationid . ']');
        unset($_REQUEST['form']);
    }
    unset($_REQUEST['save']);
} else {
    if ($_REQUEST['config'] == 4 && isset($_REQUEST['delete'])) {
        if (isset($_REQUEST['applicationid'])) {
            $result = false;
 /**
  * Add Applications
  *
  * @param _array $applications
  * @param array $app_data['name']
  * @param array $app_data['hostid']
  * @return boolean
  */
 public static function create($applications)
 {
     $applications = zbx_toArray($applications);
     $applicationids = array();
     try {
         self::BeginTransaction(__METHOD__);
         $dbHosts = CHost::get(array('output' => API_OUTPUT_SHORTEN, 'hostids' => zbx_objectValues($applications, 'hostid'), 'templated_hosts' => true, 'editable' => true, 'preservekeys' => true));
         foreach ($applications as $anum => $application) {
             if (!isset($dbHosts[$application['hostid']])) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, S_NO_PERMISSIONS);
             }
             $result = add_application($application['name'], $application['hostid']);
             if (!$result) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, S_CANNOT_CREATE_APPLICATION);
             }
             $applicationids[] = $result;
         }
         self::EndTransaction(true, __METHOD__);
         return array('applicationids' => $applicationids);
     } catch (APIException $e) {
         self::EndTransaction(false, __METHOD__);
         $error = $e->getErrors();
         $error = reset($error);
         self::setError(__METHOD__, $e->getCode(), $error);
         return false;
     }
 }
Exemplo n.º 5
0
 function EndElement($parser, $name)
 {
     if (!$this->root) {
         return false;
     }
     global $USER_DETAILS;
     $data =& $this->data[$name];
     switch ($name) {
         case XML_TAG_HOST:
             if ($data['skip'] || !isset($data['hostid']) || !$data['hostid']) {
                 break;
             }
             // case
             if (!isset($data['port'])) {
                 $data['port'] = 10050;
             }
             if (!isset($data['status'])) {
                 $data['status'] = 0;
             }
             if (!isset($data['useip'])) {
                 $data['useip'] = 0;
             }
             if (!isset($data['dns'])) {
                 $data['dns'] = '';
             }
             if (!isset($data['ip'])) {
                 $data['ip'] = '';
             }
             if (!isset($data['proxy'])) {
                 $data['proxy'] = '';
             }
             if (!zbx_empty($data['proxy'])) {
                 $sql = 'SELECT hostid ' . ' FROM hosts ' . ' WHERE host=' . zbx_dbstr($data['proxy']) . ' AND status=' . HOST_STATUS_PROXY . ' AND ' . DBin_node('hostid', get_current_nodeid(false));
                 if ($host_data = DBfetch(DBselect($sql))) {
                     $data['proxy'] = $host_data['hostid'];
                 } else {
                     $data['proxy'] = 0;
                 }
             } else {
                 $data['proxy'] = 0;
             }
             if (update_host($data['hostid'], $data['name'], $data['port'], $data['status'], $data['useip'], $data['dns'], $data['ip'], $data['proxy'], $data['templates'], 'no', '', 623, -1, 2, '', '', null, $data['groups'])) {
                 info('Host [' . $data['name'] . '] updated');
             }
             break;
             // case
             // based on mod by scricca
         // case
         // based on mod by scricca
         case XML_TAG_HOSTPROFILE:
             if (!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid']) {
                 break;
             }
             //case
             if (!isset($data['devicetype'])) {
                 $data['devicetype'] = '';
             }
             if (!isset($data['name'])) {
                 $data['name'] = '';
             }
             if (!isset($data['os'])) {
                 $data['os'] = '';
             }
             if (!isset($data['serialno'])) {
                 $data['serialno'] = '';
             }
             if (!isset($data['tag'])) {
                 $data['tag'] = '';
             }
             if (!isset($data['macaddress'])) {
                 $data['macaddress'] = '';
             }
             if (!isset($data['hardware'])) {
                 $data['hardware'] = '';
             }
             if (!isset($data['software'])) {
                 $data['software'] = '';
             }
             if (!isset($data['contact'])) {
                 $data['contact'] = '';
             }
             if (!isset($data['location'])) {
                 $data['location'] = '';
             }
             if (!isset($data['notes'])) {
                 $data['notes'] = '';
             }
             delete_host_profile($this->data[XML_TAG_HOST]['hostid']);
             if (add_host_profile($this->data[XML_TAG_HOST]['hostid'], $data['devicetype'], $data['name'], $data['os'], $data['serialno'], $data['tag'], $data['macaddress'], $data['hardware'], $data['software'], $data['contact'], $data['location'], $data['notes'])) {
                 info('Host Profile [' . $this->data[XML_TAG_HOST]['name'] . '] updated');
             }
             break;
             // case
             //---
             // Extended profiles
         // case
         //---
         // Extended profiles
         case XML_TAG_HOSTPROFILE_EXT:
             if (!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid']) {
                 break;
             }
             //case
             if (!isset($data['device_alias'])) {
                 $data['device_alias'] = '';
             }
             if (!isset($data['device_type'])) {
                 $data['device_type'] = '';
             }
             if (!isset($data['device_chassis'])) {
                 $data['device_chassis'] = '';
             }
             if (!isset($data['device_os'])) {
                 $data['device_os'] = '';
             }
             if (!isset($data['device_os_short'])) {
                 $data['device_os_short'] = '';
             }
             if (!isset($data['device_hw_arch'])) {
                 $data['device_hw_arch'] = '';
             }
             if (!isset($data['device_serial'])) {
                 $data['device_serial'] = '';
             }
             if (!isset($data['device_model'])) {
                 $data['device_model'] = '';
             }
             if (!isset($data['device_tag'])) {
                 $data['device_tag'] = '';
             }
             if (!isset($data['device_vendor'])) {
                 $data['device_vendor'] = '';
             }
             if (!isset($data['device_contract'])) {
                 $data['device_contract'] = '';
             }
             if (!isset($data['device_who'])) {
                 $data['device_who'] = '';
             }
             if (!isset($data['device_status'])) {
                 $data['device_status'] = '';
             }
             if (!isset($data['device_app_01'])) {
                 $data['device_app_01'] = '';
             }
             if (!isset($data['device_app_02'])) {
                 $data['device_app_02'] = '';
             }
             if (!isset($data['device_app_03'])) {
                 $data['device_app_03'] = '';
             }
             if (!isset($data['device_app_04'])) {
                 $data['device_app_04'] = '';
             }
             if (!isset($data['device_app_05'])) {
                 $data['device_app_05'] = '';
             }
             if (!isset($data['device_url_1'])) {
                 $data['device_url_1'] = '';
             }
             if (!isset($data['device_url_2'])) {
                 $data['device_url_2'] = '';
             }
             if (!isset($data['device_url_3'])) {
                 $data['device_url_3'] = '';
             }
             if (!isset($data['device_networks'])) {
                 $data['device_networks'] = '';
             }
             if (!isset($data['device_notes'])) {
                 $data['device_notes'] = '';
             }
             if (!isset($data['device_hardware'])) {
                 $data['device_hardware'] = '';
             }
             if (!isset($data['device_software'])) {
                 $data['device_software'] = '';
             }
             if (!isset($data['ip_subnet_mask'])) {
                 $data['ip_subnet_mask'] = '';
             }
             if (!isset($data['ip_router'])) {
                 $data['ip_router'] = '';
             }
             if (!isset($data['ip_macaddress'])) {
                 $data['ip_macaddress'] = '';
             }
             if (!isset($data['oob_ip'])) {
                 $data['oob_ip'] = '';
             }
             if (!isset($data['oob_subnet_mask'])) {
                 $data['oob_subnet_mask'] = '';
             }
             if (!isset($data['oob_router'])) {
                 $data['oob_router'] = '';
             }
             if (!isset($data['date_hw_buy'])) {
                 $data['date_hw_buy'] = '';
             }
             if (!isset($data['date_hw_install'])) {
                 $data['date_hw_install'] = '';
             }
             if (!isset($data['date_hw_expiry'])) {
                 $data['date_hw_expiry'] = '';
             }
             if (!isset($data['date_hw_decomm'])) {
                 $data['date_hw_decomm'] = '';
             }
             if (!isset($data['site_street_1'])) {
                 $data['site_street_1'] = '';
             }
             if (!isset($data['site_street_2'])) {
                 $data['site_street_2'] = '';
             }
             if (!isset($data['site_street_3'])) {
                 $data['site_street_3'] = '';
             }
             if (!isset($data['site_city'])) {
                 $data['site_city'] = '';
             }
             if (!isset($data['site_state'])) {
                 $data['site_state'] = '';
             }
             if (!isset($data['site_country'])) {
                 $data['site_country'] = '';
             }
             if (!isset($data['site_zip'])) {
                 $data['site_zip'] = '';
             }
             if (!isset($data['site_rack'])) {
                 $data['site_rack'] = '';
             }
             if (!isset($data['site_notes'])) {
                 $data['site_notes'] = '';
             }
             if (!isset($data['poc_1_name'])) {
                 $data['poc_1_name'] = '';
             }
             if (!isset($data['poc_1_email'])) {
                 $data['poc_1_email'] = '';
             }
             if (!isset($data['poc_1_phone_1'])) {
                 $data['poc_1_phone_1'] = '';
             }
             if (!isset($data['poc_1_phone_2'])) {
                 $data['poc_1_phone_2'] = '';
             }
             if (!isset($data['poc_1_cell'])) {
                 $data['poc_1_cell'] = '';
             }
             if (!isset($data['poc_1_screen'])) {
                 $data['poc_1_screen'] = '';
             }
             if (!isset($data['poc_1_notes'])) {
                 $data['poc_1_notes'] = '';
             }
             if (!isset($data['poc_2_name'])) {
                 $data['poc_2_name'] = '';
             }
             if (!isset($data['poc_2_email'])) {
                 $data['poc_2_email'] = '';
             }
             if (!isset($data['poc_2_phone_1'])) {
                 $data['poc_2_phone_1'] = '';
             }
             if (!isset($data['poc_2_phone_2'])) {
                 $data['poc_2_phone_2'] = '';
             }
             if (!isset($data['poc_2_cell'])) {
                 $data['poc_2_cell'] = '';
             }
             if (!isset($data['poc_2_screen'])) {
                 $data['poc_2_screen'] = '';
             }
             if (!isset($data['poc_2_notes'])) {
                 $data['poc_2_notes'] = '';
             }
             delete_host_profile_ext($this->data[XML_TAG_HOST]['hostid']);
             if (add_host_profile_ext($this->data[XML_TAG_HOST]['hostid'], $data)) {
                 info('Host Extended Profile [' . $this->data[XML_TAG_HOST]['name'] . '] updated');
             }
             break;
             // case
             //---
         // case
         //---
         case XML_TAG_GROUP:
             if (!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid']) {
                 break;
             }
             //case
             $sql = 'SELECT groupid, name ' . ' FROM groups' . ' WHERE ' . DBin_node('groupid', get_current_nodeid(false)) . ' AND name=' . zbx_dbstr($this->element_data);
             if (!($group = DBfetch(DBselect($sql)))) {
                 error('Missing group [' . $this->element_data . ']');
                 break;
                 // case
             }
             if (!isset($this->available_groups[$group['groupid']])) {
                 error('Group [' . $this->element_data . '] skipped - Access deny.');
                 break;
                 // case
             }
             $this->data[XML_TAG_HOST]['groups'][$group['groupid']] = $group['groupid'];
             break;
             // case
         // case
         case XML_TAG_DEPENDENCY:
             if (!isset($data['triggerid_down']) || !$data['triggerid_down']) {
                 break;
             }
             // case
             update_trigger($data['triggerid_down'], null, null, null, null, null, null, null, $data['triggerid_up'], null);
             break;
             // case
         // case
         case XML_TAG_DEPENDS:
             if (!isset($this->data[XML_TAG_DEPENDENCY]['triggerid_down']) || !$this->data[XML_TAG_DEPENDENCY]['triggerid_down']) {
                 break;
             }
             //case
             if (!($trigger_up = get_trigger_by_description($this->element_data))) {
                 break;
             }
             array_push($this->data[XML_TAG_DEPENDENCY]['triggerid_up'], $trigger_up['triggerid']);
             break;
             // case
         // case
         case XML_TAG_APPLICATION:
             if (!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid']) {
                 break;
             }
             //case
             if (!isset($this->data[XML_TAG_ITEM])) {
                 break;
             }
             //case
             $sql = 'SELECT applicationid ' . ' FROM applications' . ' WHERE ' . DBin_node('applicationid', get_current_nodeid(false)) . ' AND name=' . zbx_dbstr($this->element_data) . ' AND hostid=' . $this->data[XML_TAG_HOST]['hostid'];
             if (!($application = DBfetch(DBselect($sql)))) {
                 $applicationid = add_application($this->element_data, $this->data[XML_TAG_HOST]['hostid']);
             } else {
                 $applicationid = $application['applicationid'];
             }
             $this->data[XML_TAG_ITEM]['applications'][] = $applicationid;
             break;
             // case
         // case
         case XML_TAG_TEMPLATE:
             if (!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid']) {
                 break;
             }
             //case
             $sql = 'SELECT DISTINCT host, hostid ' . ' FROM hosts' . ' WHERE ' . DBin_node('hostid') . ' AND host=' . zbx_dbstr($this->element_data) . ' AND status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ',' . HOST_STATUS_TEMPLATE . ')';
             if (!($template = DBfetch(DBselect($sql)))) {
                 error('Missing template [' . $this->element_data . ']');
                 break;
                 // case
             }
             if (!isset($this->available_hosts[$template['hostid']])) {
                 error('Template [' . $this->element_data . '] skipped - Access deny.');
                 break;
                 // case
             }
             $this->data[XML_TAG_HOST]['templates'][$template["hostid"]] = $template['host'];
             break;
             // case
         // case
         case XML_TAG_ITEM:
             if (!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid']) {
                 if (isset($this->data[XML_TAG_HOST]['skip']) && $this->data[XML_TAG_HOST]['skip']) {
                     info('Item [' . $data['description'] . '] skipped - user rule for host');
                     break;
                     // case
                 }
                 error('Item [' . $data['description'] . '] skipped - missing host');
                 break;
                 // case
             }
             if (!isset($data['description'])) {
                 $data['description'] = '';
             }
             if (!isset($data['delay'])) {
                 $data['delay'] = 30;
             }
             if (!isset($data['history'])) {
                 $data['history'] = 90;
             }
             if (!isset($data['trends'])) {
                 $data['trends'] = 365;
             }
             if (!isset($data['status'])) {
                 $data['status'] = 0;
             }
             if (!isset($data['units'])) {
                 $data['units'] = '';
             }
             if (!isset($data['multiplier'])) {
                 $data['multiplier'] = 0;
             }
             if (!isset($data['delta'])) {
                 $data['delta'] = 0;
             }
             if (!isset($data['formula'])) {
                 $data['formula'] = '';
             }
             if (!isset($data['lastlogsize'])) {
                 $data['lastlogsize'] = 0;
             }
             if (!isset($data['logtimefmt'])) {
                 $data['logtimefmt'] = '';
             }
             if (!isset($data['delay_flex'])) {
                 $data['delay_flex'] = '';
             }
             if (!isset($data['trapper_hosts'])) {
                 $data['trapper_hosts'] = '';
             }
             if (!isset($data['snmp_community'])) {
                 $data['snmp_community'] = '';
             }
             if (!isset($data['snmp_oid'])) {
                 $data['snmp_oid'] = '';
             }
             if (!isset($data['snmp_port'])) {
                 $data['snmp_port'] = 161;
             }
             if (!isset($data['snmpv3_securityname'])) {
                 $data['snmpv3_securityname'] = '';
             }
             if (!isset($data['snmpv3_securitylevel'])) {
                 $data['snmpv3_securitylevel'] = 0;
             }
             if (!isset($data['snmpv3_authpassphrase'])) {
                 $data['snmpv3_authpassphrase'] = '';
             }
             if (!isset($data['snmpv3_privpassphrase'])) {
                 $data['snmpv3_privpassphrase'] = '';
             }
             if (!isset($data['valuemap'])) {
                 $data['valuemap'] = '';
             }
             if (!isset($data['params'])) {
                 $data['params'] = '';
             }
             if (!isset($data['ipmi_sensor'])) {
                 $data['ipmi_sensor'] = '';
             }
             if (!isset($data['applications'])) {
                 $data['applications'] = array();
             }
             if (!empty($data['valuemap'])) {
                 $sql = 'SELECT valuemapid ' . ' FROM valuemaps ' . ' WHERE ' . DBin_node('valuemapid', get_current_nodeid(false)) . ' AND name=' . zbx_dbstr($data['valuemap']);
                 if ($valuemap = DBfetch(DBselect($sql))) {
                     $data['valuemapid'] = $valuemap['valuemapid'];
                 } else {
                     $data['valuemapid'] = add_valuemap($data['valuemap'], array());
                 }
             }
             $sql = 'SELECT itemid,valuemapid,templateid ' . ' FROM items ' . ' WHERE key_=' . zbx_dbstr($data['key']) . ' AND hostid=' . $this->data[XML_TAG_HOST]['hostid'] . ' AND ' . DBin_node('itemid', get_current_nodeid(false));
             if ($item = DBfetch(DBselect($sql))) {
                 /* exist */
                 if ($this->item['exist'] == 1) {
                     info('Item [' . $data['description'] . '] skipped - user rule');
                     break;
                 }
                 if (!isset($data['valuemapid'])) {
                     $data['valuemapid'] = $item['valuemapid'];
                 }
                 $data['key_'] = $data['key'];
                 $data['hostid'] = $this->data[XML_TAG_HOST]['hostid'];
                 $data['applications'] = array_unique(array_merge($data['applications'], get_applications_by_itemid($item['itemid'])));
                 $data['templateid'] = $item['templateid'];
                 check_db_fields($item, $data);
                 update_item($item['itemid'], $data);
             } else {
                 /* missed */
                 if ($this->item['missed'] == 1) {
                     info('Item [' . $data['description'] . '] skipped - user rule');
                     break;
                     // case
                 }
                 if (!isset($data['valuemapid'])) {
                     $data['valuemapid'] = 0;
                 }
                 $data['hostid'] = $this->data[XML_TAG_HOST]['hostid'];
                 $data['key_'] = $data['key'];
                 add_item($data);
             }
             break;
             // case
         // case
         case XML_TAG_TRIGGER:
             if (!isset($data['expression'])) {
                 $data['expression'] = '';
             }
             if (!isset($data['description'])) {
                 $data['description'] = '';
             }
             if (!isset($data['type'])) {
                 $data['type'] = 0;
             }
             if (!isset($data['priority'])) {
                 $data['priority'] = 0;
             }
             if (!isset($data['status'])) {
                 $data['status'] = 0;
             }
             if (!isset($data['comments'])) {
                 $data['comments'] = '';
             }
             if (!isset($data['url'])) {
                 $data['url'] = '';
             }
             if (!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid']) {
                 if (isset($this->data[XML_TAG_HOST]['skip']) && $this->data[XML_TAG_HOST]['skip']) {
                     // remember skipped triggers for dependencies
                     $this->data[XML_TAG_DEPENDENCIES]['skip'][] = $this->data[XML_TAG_HOST]['name'] . ':' . $data['description'];
                     info('Trigger [' . $data['description'] . '] skipped - user rule for host');
                     break;
                     // case
                 }
                 if (zbx_strstr($data['expression'], '{HOSTNAME}')) {
                     // remember skipped triggers for dependencies
                     $this->data[XML_TAG_DEPENDENCIES]['skip'][] = $this->data[XML_TAG_HOST]['name'] . ':' . $data['description'];
                     error('Trigger [' . $data['description'] . '] skipped - missing host');
                     break;
                     // case
                 }
             } else {
                 $data['expression'] = str_replace('{{HOSTNAME}:', '{' . $this->data[XML_TAG_HOST]['name'] . ':', $data['expression']);
                 $result = DBselect('SELECT DISTINCT t.triggerid,t.templateid,t.expression ' . ' FROM triggers t,functions f,items i ' . ' WHERE t.triggerid=f.triggerid ' . ' AND f.itemid=i.itemid' . ' AND i.hostid=' . $this->data[XML_TAG_HOST]['hostid'] . ' AND t.description=' . zbx_dbstr($data['description']));
                 while ($trigger = DBfetch($result)) {
                     if (explode_exp($trigger['expression'], 0) == $data['expression']) {
                         break;
                         // while
                     }
                 }
                 if (!empty($trigger)) {
                     /* exist */
                     if ($this->trigger['exist'] == 1) {
                         /* skip */
                         // remember skipped triggers for dependencies
                         $this->data[XML_TAG_DEPENDENCIES]['skip'][] = $this->data[XML_TAG_HOST]['name'] . ':' . $data['description'];
                         info('Trigger [' . $data['description'] . '] skipped - user rule');
                         break;
                         // case
                     }
                     update_trigger($trigger['triggerid'], $data['expression'], $data['description'], $data['type'], $data['priority'], $data['status'], $data['comments'], $data['url'], get_trigger_dependencies_by_triggerid($trigger['triggerid']), $trigger['templateid']);
                     break;
                     // case
                 } else {
                     /* missed */
                     // continue [add_trigger]
                 }
             }
             if ($this->trigger['missed'] == 1) {
                 // remember skipped triggers for dependencies
                 $this->data[XML_TAG_DEPENDENCIES]['skip'][] = $this->data[XML_TAG_HOST]['name'] . ':' . $data['description'];
                 info('Trigger [' . $data['description'] . '] skipped - user rule');
                 break;
                 // case
             }
             add_trigger($data['expression'], $data['description'], $data['type'], $data['priority'], $data['status'], $data['comments'], $data['url']);
             break;
             // case
         // case
         case XML_TAG_GRAPH:
             if (isset($data['error'])) {
                 error('Graph [' . $data['name'] . '] skipped - error occured');
                 break;
                 // case
             }
             if (!isset($data['ymin_type'])) {
                 $data['ymin_type'] = 0;
             }
             if (!isset($data['ymax_type'])) {
                 $data['ymax_type'] = 0;
             }
             if (!isset($data['ymin_item_key'])) {
                 $data['ymin_item_key'] = '';
             }
             if (!isset($data['ymax_item_key'])) {
                 $data['ymax_item_key'] = '';
             }
             if (!isset($data['ymin_itemid'])) {
                 $data['ymin_itemid'] = 0;
             }
             if (!isset($data['ymax_itemid'])) {
                 $data['ymax_itemid'] = 0;
             }
             if (!isset($data['show_work_period'])) {
                 $data['show_work_period'] = 1;
             }
             if (!isset($data['show_triggers'])) {
                 $data['show_triggers'] = 1;
             }
             if (!isset($data['graphtype'])) {
                 $data['graphtype'] = 0;
             }
             if (!isset($data['yaxismin'])) {
                 $data['yaxismin'] = 0;
             }
             if (!isset($data['yaxismax'])) {
                 $data['yaxismax'] = 0;
             }
             if (!isset($data['show_legend'])) {
                 $data['show_legend'] = 0;
             }
             if (!isset($data['show_3d'])) {
                 $data['show_3d'] = 0;
             }
             if (!isset($data['percent_left'])) {
                 $data['percent_left'] = 0;
             }
             if (!isset($data['percent_right'])) {
                 $data['percent_right'] = 0;
             }
             if (!isset($data['items'])) {
                 $data['items'] = array();
             }
             if (!empty($data['ymin_item_key'])) {
                 $data['ymin_item_key'] = explode(':', $data['ymin_item_key']);
                 if (count($data['ymin_item_key']) < 2) {
                     $this->data[XML_TAG_GRAPH]['error'] = true;
                     error('Incorrect y min item for graph [' . $data['name'] . ']');
                     break;
                     // case
                 }
                 $data['host'] = array_shift($data['ymin_item_key']);
                 $data['ymin_item_key'] = implode(':', $data['ymin_item_key']);
                 if (!($item = get_item_by_key($data['ymin_item_key'], $data['host']))) {
                     $this->data[XML_TAG_GRAPH]['error'] = true;
                     error('Missed item [' . $data['ymin_item_key'] . '] for host [' . $data['host'] . ']');
                     break;
                     // case
                 }
                 $data['ymin_itemid'] = $item['itemid'];
             }
             if (!empty($data['ymax_item_key'])) {
                 $data['ymax_item_key'] = explode(':', $data['ymax_item_key']);
                 if (count($data['ymax_item_key']) < 2) {
                     $this->data[XML_TAG_GRAPH]['error'] = true;
                     error('Incorrect y max item for graph [' . $data['name'] . ']');
                     break;
                     // case
                 }
                 $data['host'] = array_shift($data['ymax_item_key']);
                 $data['ymax_item_key'] = implode(':', $data['ymax_item_key']);
                 if (!($item = get_item_by_key($data['ymax_item_key'], $data['host']))) {
                     $this->data[XML_TAG_GRAPH]['error'] = true;
                     error('Missed item [' . $data['ymax_item_key'] . '] for host [' . $data['host'] . ']');
                     break;
                     // case
                 }
                 $data['ymax_itemid'] = $item['itemid'];
             }
             if (!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid']) {
                 if (isset($this->data[XML_TAG_HOST]['skip']) && $this->data[XML_TAG_HOST]['skip']) {
                     info('Graph [' . $data['name'] . '] skipped - user rule for host');
                     break;
                     // case
                 }
                 foreach ($data['items'] as $id) {
                     if (zbx_strstr($data['name'], '{HOSTNAME}')) {
                         error('Graph [' . $data['name'] . '] skipped - missing host');
                         break;
                         // case
                     }
                 }
             } else {
                 if ($graph = DBfetch(DBselect('SELECT DISTINCT g.graphid, g.templateid' . ' FROM graphs g, graphs_items gi, items i' . ' WHERE g.graphid=gi.graphid ' . ' AND gi.itemid=i.itemid' . ' AND g.name=' . zbx_dbstr($data['name']) . ' AND i.hostid=' . $this->data[XML_TAG_HOST]['hostid']))) {
                     /* exist */
                     if ($this->graph['exist'] == 1) {
                         /* skip */
                         info('Graph [' . $data['name'] . '] skipped - user rule');
                         break;
                         // case
                     }
                     $data['graphid'] = $graph['graphid'];
                     update_graph_with_items($data['graphid'], $data['name'], $data['width'], $data['height'], $data['ymin_type'], $data['ymax_type'], $data['yaxismin'], $data['yaxismax'], $data['ymin_itemid'], $data['ymax_itemid'], $data['show_work_period'], $data['show_triggers'], $data['graphtype'], $data['show_legend'], $data['show_3d'], $data['percent_left'], $data['percent_right'], $data['items'], $graph['templateid']);
                 } else {
                     /* missed */
                     // continue [add_group]
                 }
             }
             if (!isset($data['graphid'])) {
                 if ($this->graph['missed'] == 1) {
                     /* skip */
                     info('Graph [' . $data['name'] . '] skipped - user rule');
                     break;
                     // case
                 }
                 $data['graphid'] = add_graph_with_items($data['name'], $data['width'], $data['height'], $data['ymin_type'], $data['ymax_type'], $data['yaxismin'], $data['yaxismax'], $data['ymin_itemid'], $data['ymax_itemid'], $data['show_work_period'], $data['show_triggers'], $data['graphtype'], $data['show_legend'], $data['show_3d'], $data['percent_left'], $data['percent_right'], $data['items']);
             }
             break;
             // case
         // case
         case XML_TAG_GRAPH_ELEMENT:
             if (!isset($this->data[XML_TAG_GRAPH])) {
                 break;
             }
             // case
             $data['key'] = explode(':', $data['item']);
             if (count($data['key']) < 2) {
                 $this->data[XML_TAG_GRAPH]['error'] = true;
                 error('Incorrect element for graph [' . $data['name'] . ']');
                 break;
                 // case
             }
             $data['host'] = array_shift($data['key']);
             $data['key'] = implode(':', $data['key']);
             if (isset($this->data[XML_TAG_HOST]['name'])) {
                 $data['host'] = str_replace('{HOSTNAME}', $this->data[XML_TAG_HOST]['name'], $data['host']);
             }
             if (!isset($data['drawtype'])) {
                 $data['drawtype'] = 0;
             }
             if (!isset($data['sortorder'])) {
                 $data['sortorder'] = 0;
             }
             if (!isset($data['color'])) {
                 $data['color'] = 'Dark Green';
             }
             if (!isset($data['yaxisside'])) {
                 $data['yaxisside'] = 1;
             }
             if (!isset($data['calc_fnc'])) {
                 $data['calc_fnc'] = 2;
             }
             if (!isset($data['type'])) {
                 $data['type'] = 0;
             }
             if (!isset($data['periods_cnt'])) {
                 $data['periods_cnt'] = 5;
             }
             if (!($item = get_item_by_key($data['key'], $data['host']))) {
                 $this->data[XML_TAG_GRAPH]['error'] = true;
                 error('Missing item [' . $data['key'] . '] for host [' . $data['host'] . ']');
                 break;
                 // case
             }
             $data['itemid'] = $item['itemid'];
             array_push($this->data[XML_TAG_GRAPH]['items'], $data);
             break;
             // case
             /*case XML_TAG_SCREEN:
             		case XML_TAG_SCREEN_ELEMENT:
             			break; // case*/
         // case
         /*case XML_TAG_SCREEN:
         		case XML_TAG_SCREEN_ELEMENT:
         			break; // case*/
         default:
             if (isset($this->sub_node) && isset($this->main_node)) {
                 $main_node = array_pop($this->main_node);
                 $this->data[$main_node][$this->sub_node] = $this->element_data;
                 array_push($this->main_node, $main_node);
             }
             $this->sub_node = null;
             return;
     }
     unset($this->data[$name], $data);
     array_pop($this->main_node);
 }
Exemplo n.º 6
0
function db_save_httptest($httptestid, $hostid, $application, $name, $delay, $status, $agent, $macros, $steps)
{
    $history = 30;
    // TODO !!! Allow user set this parametr
    $trends = 90;
    // TODO !!! Allow user set this parametr
    if (!eregi('^([0-9a-zA-Z\\_\\.[.-.]\\$ ]+)$', $name)) {
        error("Scenario name should contain '0-9a-zA-Z_.\$ '- characters only");
        return false;
    }
    DBstart();
    if ($applicationid = DBfetch(DBselect('select applicationid from applications ' . ' where name=' . zbx_dbstr($application) . ' and hostid=' . $hostid))) {
        $applicationid = $applicationid['applicationid'];
    } else {
        $applicationid = add_application($application, $hostid);
        if (!$applicationid) {
            error('Can\'t add new application. [' . $application . ']');
            return false;
        }
    }
    if (isset($httptestid)) {
        $result = DBexecute('update httptest set ' . ' applicationid=' . $applicationid . ', name=' . zbx_dbstr($name) . ', delay=' . $delay . ',' . ' status=' . $status . ', agent=' . zbx_dbstr($agent) . ', macros=' . zbx_dbstr($macros) . ',' . ' error=' . zbx_dbstr('') . ', curstate=' . HTTPTEST_STATE_UNKNOWN . ' where httptestid=' . $httptestid);
    } else {
        $httptestid = get_dbid("httptest", "httptestid");
        if (DBfetch(DBselect('select t.httptestid from httptest t, applications a where t.applicationid=a.applicationid ' . ' and a.hostid=' . $hostid . ' and t.name=' . zbx_dbstr($name)))) {
            error('Scenario with name [' . $name . '] already exist');
            return false;
        }
        $result = DBexecute('insert into httptest' . ' (httptestid, applicationid, name, delay, status, agent, macros, curstate) ' . ' values (' . $httptestid . ',' . $applicationid . ',' . zbx_dbstr($name) . ',' . $delay . ',' . $status . ',' . zbx_dbstr($agent) . ',' . zbx_dbstr($macros) . ',' . HTTPTEST_STATE_UNKNOWN . ')');
        $test_added = true;
    }
    if ($result) {
        $httpstepids = array();
        foreach ($steps as $sid => $s) {
            if (!isset($s['name'])) {
                $s['name'] = '';
            }
            if (!isset($s['timeout'])) {
                $s['timeout'] = 15;
            }
            if (!isset($s['url'])) {
                $s['url'] = '';
            }
            if (!isset($s['posts'])) {
                $s['posts'] = '';
            }
            if (!isset($s['required'])) {
                $s['required'] = '';
            }
            if (!isset($s['status_codes'])) {
                $s['status_codes'] = '';
            }
            $result = db_save_step($hostid, $applicationid, $httptestid, $name, $s['name'], $sid + 1, $s['timeout'], $s['url'], $s['posts'], $s['required'], $s['status_codes'], $delay, $history, $trends);
            if (!$result) {
                break;
            }
            $httpstepids[$result] = $result;
        }
        if ($result) {
            /* clean unneeded steps */
            $db_steps = DBselect('select httpstepid from httpstep where httptestid=' . $httptestid);
            while ($step_data = DBfetch($db_steps)) {
                if (isset($httpstepids[$step_data['httpstepid']])) {
                    continue;
                }
                delete_httpstep($step_data['httpstepid']);
            }
        }
    }
    if ($result) {
        $monitored_items = array(array('description' => 'Download speed for scenario \'$1\'', 'key_' => 'web.test.in[' . $name . ',,bps]', 'type' => ITEM_VALUE_TYPE_FLOAT, 'units' => 'bps', 'httptestitemtype' => HTTPSTEP_ITEM_TYPE_IN), array('description' => 'Failed step of scenario \'$1\'', 'key_' => 'web.test.fail[' . $name . ']', 'type' => ITEM_VALUE_TYPE_UINT64, 'units' => '', 'httptestitemtype' => HTTPSTEP_ITEM_TYPE_LASTSTEP));
        foreach ($monitored_items as $item) {
            $item_data = DBfetch(DBselect('select i.itemid,i.history,i.trends,i.status,i.delta,i.valuemapid ' . ' from items i, httptestitem hi ' . ' where hi.httptestid=' . $httptestid . ' and hi.itemid=i.itemid ' . ' and hi.type=' . $item['httptestitemtype']));
            if (!$item_data) {
                $item_data = DBfetch(DBselect('select i.itemid,i.history,i.trends,i.status,i.delta,i.valuemapid ' . ' from items i where i.key_=' . zbx_dbstr($item['key_']) . ' and i.hostid=' . $hostid));
            }
            $item_args = array('description' => $item['description'], 'key_' => $item['key_'], 'hostid' => $hostid, 'delay' => $delay, 'type' => ITEM_TYPE_HTTPTEST, 'snmp_community' => '', 'snmp_oid' => '', 'value_type' => $item['type'], 'data_type' => ITEM_DATA_TYPE_DECIMAL, 'trapper_hosts' => 'localhost', 'snmp_port' => 161, 'units' => $item['units'], 'multiplier' => 0, 'snmpv3_securityname' => '', 'snmpv3_securitylevel' => 0, 'snmpv3_authpassphrase' => '', 'snmpv3_privpassphrase' => '', 'formula' => 0, 'logtimefmt' => '', 'delay_flex' => '', 'params' => '', 'ipmi_sensor' => '', 'applications' => array($applicationid));
            if (!$item_data) {
                $item_args['history'] = $history;
                $item_args['status'] = ITEM_STATUS_ACTIVE;
                $item_args['delta'] = 0;
                $item_args['trends'] = $trends;
                $item_args['valuemapid'] = 0;
                if (!($itemid = add_item($item_args))) {
                    $result = false;
                    break;
                }
            } else {
                $itemid = $item_data['itemid'];
                $item_args['history'] = $item_data['history'];
                $item_args['status'] = $item_data['status'];
                $item_args['delta'] = $item_data['delta'];
                $item_args['trends'] = $item_data['trends'];
                $item_args['valuemapid'] = $item_data['valuemapid'];
                if (!update_item($itemid, $item_args)) {
                    $result = false;
                    break;
                }
            }
            $httptestitemid = get_dbid('httptestitem', 'httptestitemid');
            DBexecute('delete from httptestitem where itemid=' . $itemid);
            if (!DBexecute('insert into httptestitem' . ' (httptestitemid, httptestid, itemid, type) ' . ' values (' . $httptestitemid . ',' . $httptestid . ',' . $itemid . ',' . $item['httptestitemtype'] . ')')) {
                $result = false;
                break;
            }
        }
    }
    if (!$result && isset($test_added)) {
        delete_httptest($httptestid);
    } else {
        $restult = $httptestid;
    }
    DBend($result);
    return $result;
}
Exemplo n.º 7
0
     }
     $result = update_host($_REQUEST['hostid'], $_REQUEST['host'], $_REQUEST['port'], $_REQUEST['status'], $useip, $_REQUEST['dns'], $_REQUEST['ip'], $_REQUEST['proxy_hostid'], $templates, $useipmi, $_REQUEST['ipmi_ip'], $_REQUEST['ipmi_port'], $_REQUEST['ipmi_authtype'], $_REQUEST['ipmi_privilege'], $_REQUEST['ipmi_username'], $_REQUEST['ipmi_password'], $_REQUEST['newgroup'], $groups);
     $msg_ok = S_HOST_UPDATED;
     $msg_fail = S_CANNOT_UPDATE_HOST;
     $hostid = $_REQUEST['hostid'];
 } else {
     $hostid = $result = add_host($_REQUEST['host'], $_REQUEST['port'], $_REQUEST['status'], $useip, $_REQUEST['dns'], $_REQUEST['ip'], $_REQUEST['proxy_hostid'], $templates, $useipmi, $_REQUEST['ipmi_ip'], $_REQUEST['ipmi_port'], $_REQUEST['ipmi_authtype'], $_REQUEST['ipmi_privilege'], $_REQUEST['ipmi_username'], $_REQUEST['ipmi_password'], $_REQUEST['newgroup'], $groups);
     $msg_ok = S_HOST_ADDED;
     $msg_fail = S_CANNOT_ADD_HOST;
 }
 if (!zbx_empty($hostid) && $hostid && $clone_hostid && $_REQUEST['form'] == 'full_clone') {
     // Host applications
     $sql = 'SELECT * FROM applications WHERE hostid=' . $clone_hostid . ' AND templateid=0';
     $res = DBselect($sql);
     while ($db_app = DBfetch($res)) {
         add_application($db_app['name'], $hostid, 0);
     }
     // Host items
     $sql = 'SELECT DISTINCT i.itemid, i.description ' . ' FROM items i ' . ' WHERE i.hostid=' . $clone_hostid . ' AND i.templateid=0 ' . ' ORDER BY i.description';
     $res = DBselect($sql);
     while ($db_item = DBfetch($res)) {
         $result &= copy_item_to_host($db_item['itemid'], $hostid, true);
     }
     // Host triggers
     $available_triggers = get_accessible_triggers(PERM_READ_ONLY, array($clone_hostid), PERM_RES_IDS_ARRAY);
     $sql = 'SELECT DISTINCT t.triggerid, t.description ' . ' FROM triggers t, items i, functions f' . ' WHERE i.hostid=' . $clone_hostid . ' AND f.itemid=i.itemid ' . ' AND t.triggerid=f.triggerid ' . ' AND ' . DBcondition('t.triggerid', $available_triggers) . ' AND t.templateid=0 ' . ' ORDER BY t.description';
     $res = DBselect($sql);
     while ($db_trig = DBfetch($res)) {
         $result &= copy_trigger_to_host($db_trig['triggerid'], $hostid, true);
     }
     // Host graphs
Exemplo n.º 8
0
             $item[$field] = null;
         }
     }
     if ($new_appid) {
         $result = smart_update_item($_REQUEST['itemid'], $item);
     }
     $result = DBend($result);
     $itemid = $_REQUEST['itemid'];
     /*			$action = AUDIT_ACTION_UPDATE;*/
     show_messages($result, S_ITEM_UPDATED, S_CANNOT_UPDATE_ITEM);
 } else {
     DBstart();
     $new_appid = true;
     $itemid = false;
     if (!zbx_empty($_REQUEST['new_application'])) {
         if ($new_appid = add_application($_REQUEST['new_application'], $_REQUEST['hostid'])) {
             $applications[$new_appid] = $new_appid;
         }
     }
     $item['applications'] = $applications;
     if ($new_appid) {
         $itemid = add_item($item);
     }
     $result = DBend($itemid);
     /*			$action = AUDIT_ACTION_ADD;*/
     show_messages($result, S_ITEM_ADDED, S_CANNOT_ADD_ITEM);
 }
 if ($result) {
     /*			$host = get_host_by_hostid($_REQUEST['hostid']);
     
     			add_audit($action, AUDIT_RESOURCE_ITEM, S_ITEM.' ['.$_REQUEST['key'].'] ['.$itemid.'] '.S_HOST.' ['.$host['host'].']');*/
Exemplo n.º 9
0
     include './view_resume.php';
 } else {
     if ($action == 'submit_resume') {
         //GET JOB ID & RESUME ID FROM SELECT FORM
         if ($_GET['job_id'] && $_GET['resume_id']) {
             $job_id = $_GET['job_id'];
             $resume_id = $_GET['resume_id'];
             $job = get_job_by_id($job_id);
             // GET JOB DATA
             $job_title = $job['jobTitle'];
             $job_type = $job['jobType'];
             $job_city = $job['city'];
             $job_state = $job['state'];
             $job_summary = $job['summary'];
             $job_description = $job['description'];
             $query = add_application($job_id, $resume_id);
             $submitted = '1';
             $message = "Your resume has been submitted for this job.";
         } else {
             $message = "No Job ID or Resume provided.";
         }
         include './view_job.php';
     } else {
         if ($action == 'apply') {
             $job_id = $_GET['job_id'];
             $job_title = $_GET['job_title'];
             $user_id = $_GET['user_id'];
             $resumes = get_resume_by_user($user_id);
             $job = get_job_by_id($job_id);
             include './select_resume.php';
         } else {
Exemplo n.º 10
0
         $templateid = reset($result['templateids']);
     } else {
         error(CTemplate::resetErrors());
         $result = false;
     }
     $msg_ok = S_TEMPLATE_ADDED;
     $msg_fail = S_CANNOT_ADD_TEMPLATE;
 }
 // }}} CREATE/UPDATE TEMPLATE
 // FULL_CLONE {
 if (!zbx_empty($templateid) && $templateid && $clone_templateid && $_REQUEST['form'] == 'full_clone') {
     // Host applications
     $sql = 'SELECT * FROM applications WHERE hostid=' . $clone_templateid . ' AND templateid=0';
     $res = DBselect($sql);
     while ($db_app = DBfetch($res)) {
         add_application($db_app['name'], $templateid, 0);
     }
     // Host items
     $sql = 'SELECT DISTINCT i.itemid, i.description ' . ' FROM items i ' . ' WHERE i.hostid=' . $clone_templateid . ' AND i.templateid=0 ' . ' ORDER BY i.description';
     $res = DBselect($sql);
     while ($db_item = DBfetch($res)) {
         $result &= (bool) copy_item_to_host($db_item['itemid'], $templateid, true);
     }
     // Host triggers
     $result &= copy_triggers($clone_templateid, $templateid);
     // Host graphs
     $options = array('hostids' => $clone_templateid, 'inherited' => 0, 'output' => API_OUTPUT_REFER);
     $db_graphs = CGraph::get($options);
     foreach ($db_graphs as $gnum => $db_graph) {
         $result &= (bool) copy_graph_to_host($db_graph['graphid'], $templateid, true);
     }