/** * test_add_key * * @access public * @return void */ public function test_add_key() { $data = array('device_name' => 'lan-116'); $property_key = sw_member::property_factory('device_key', $data); $device = sw_member::operator_factory('device', $property_key); $device_key = $device->get_operator('key')->add_key(); $query_device_key_table = $this->getConnection()->CreateQueryTable('device_key', 'select * from device_key'); $query_seq_g_table = $this->getConnection()->CreateQueryTable('sequence_global', 'select * from sequence_global where table_name="device_key"'); $expect_device_key = $this->createXMLDataSet(dirname(__FILE__) . '/_files/add_result.xml')->getTable('device_key'); $expect_seq_g = $this->createXMLDataSet(dirname(__FILE__) . '/_files/add_result.xml')->getTable('sequence_global'); $this->assertTablesEqual($expect_device_key, $query_device_key_table); $this->assertTablesEqual($expect_seq_g, $query_seq_g_table); }
/** * 修改监控适配器 * * @access public * @return void */ public function action_mod() { $madapter_name = $this->__request->get_post('name', ''); $madapter_id = $this->__request->get_post('madapter_id', ''); $madapter_display_name = $this->__request->get_post('display_name', ''); $steps = $this->__request->get_post('steps', ''); $store_type = $this->__request->get_post('store_type', ''); $madapter_type = $this->__request->get_post('madapter_type', ''); if (!$madapter_id) { return $this->render_json(null, 10001, '`madapter_id` not allow is empty.'); } if ($madapter_display_name) { $data['madapter_display_name'] = $madapter_display_name; } if ($steps) { $data['steps'] = $steps; } if ($store_type) { $data['store_type'] = $store_type; } if ($madapter_type) { $data['madapter_type'] = $madapter_type; } if ($madapter_name) { $data['madapter_name'] = $madapter_name; } // 修改 madapter basic try { $property_basic = sw_member::property_factory('madapter_basic', $data); $condition = sw_member::condition_factory('mod_madapter_basic', array('madapter_id' => $madapter_id)); $condition->set_in('madapter_id'); $condition->set_property($property_basic); $madapter = sw_member::operator_factory('madapter'); $madapter->get_operator('basic')->mod_basic($condition); } catch (\swan\exception\sw_exception $e) { return $this->render_json(null, 10002, $e->getMessage()); } return $this->render_json(null, 10000, 'mod madapter success.'); }
/** * 修改监控适配器数据项 * * @access public * @return void */ public function action_mod() { $mid = $this->__request->get_post('madapter_id', ''); $mmid = $this->__request->get_post('metric_id', ''); $name = $this->__request->get_post('name', ''); $unit = $this->__request->get_post('unit', ''); $title = $this->__request->get_post('title', ''); $tmax = $this->__request->get_post('tmax', ''); $vmax = $this->__request->get_post('vmax', 'U'); $vmin = $this->__request->get_post('vmin', 'U'); $dst_type = $this->__request->get_post('dst_type', ''); $collect_every = $this->__request->get_post('collect_every', ''); $time_threshold = $this->__request->get_post('time_threshold', ''); if (!$mid || !$mmid) { return $this->render_json(null, 10001, '`madapter_id` and `metric_id` not allow is empty.'); } // 修改 madapter metric $data = array(); if ($name) { $data['metric_name'] = $name; } if ($title) { $data['title'] = $title; } if ($unit) { $data['unit'] = $unit; } if ($collect_every) { $data['collect_every'] = $collect_every; } if ($time_threshold) { $data['time_threshold'] = $time_threshold; } if ($dst_type) { $data['dst_type'] = $dst_type; } if ($vmax) { $data['vmax'] = $vmax; } if ($vmin) { $data['vmin'] = $vmin; } if ($tmax) { $data['tmax'] = $tmax; } try { $property_metric = sw_member::property_factory('madapter_metric', $data); $condition = sw_member::condition_factory('mod_madapter_metric', array('madapter_id' => $mid, 'metric_id' => $mmid)); $condition->set_in('madapter_id'); $condition->set_in('metric_id'); $condition->set_property($property_metric); $madapter = sw_member::operator_factory('madapter'); $madapter->get_operator('metric')->mod_metric($condition); } catch (\swan\exception\sw_exception $e) { return $this->render_json(null, 10002, $e->getMessage()); } return $this->render_json(null, 10000, 'mod madapter metric success.'); }
/** * test_mod_archive * * @access public * @return void */ public function test_mod_archive() { $data = array('title' => '2month', 'steps' => 24, 'rows' => 775); $property_archive = sw_member::property_factory('madapter_archive', $data); $condition = sw_member::condition_factory('mod_madapter_archive', array('archive_id' => 2, 'madapter_id' => 1)); $condition->set_property($property_archive); $condition->set_in('madapter_id'); $condition->set_in('archive_id'); $madapter = sw_member::operator_factory('madapter'); $madapter->get_operator('archive')->mod_archive($condition); $query_table = $this->getConnection()->CreateQueryTable('madapter_archive', 'select * from madapter_archive'); $expect = $this->createXMLDataSet(dirname(__FILE__) . '/_files/mod_result.xml')->getTable('madapter_archive'); $this->assertTablesEqual($expect, $query_table); }
/** * test_mod_basic * * @access public * @return void */ public function test_mod_basic() { $data = array('steps' => 350, 'madapter_name' => 'ngnix', 'madapter_display_name' => 'ngnix监控适配器', 'store_type' => 2, 'madapter_type' => 2); $property_basic = sw_member::property_factory('madapter_basic', $data); $condition = sw_member::condition_factory('mod_madapter_basic', array('madapter_id' => 2)); $condition->set_property($property_basic); $condition->set_in('madapter_id'); $madapter = sw_member::operator_factory('madapter'); $madapter->get_operator('basic')->mod_basic($condition); $query_table = $this->getConnection()->CreateQueryTable('madapter_basic', 'select * from madapter_basic'); $expect = $this->createXMLDataSet(dirname(__FILE__) . '/_files/mod_result.xml')->getTable('madapter_basic'); $this->assertTablesEqual($expect, $query_table); }
/** * 修改监控适配器属性 * * @access public * @return void */ public function action_mod() { $mid = $this->__request->get_post('madapter_id', ''); $aid = $this->__request->get_post('attr_id', ''); $name = $this->__request->get_post('name', ''); $display_name = $this->__request->get_post('display_name', ''); $form_type = $this->__request->get_post('form_type', ''); $form_data = $this->__request->get_post('form_data', ''); $attr_default = $this->__request->get_post('attr_default', ''); if (!$mid || !$aid) { return $this->render_json(null, 10001, '`madapter_id` and `attr_id` not allow is empty.'); } // 修改 madapter attribute $data = array(); if ($name) { $data['attr_name'] = $name; } if ($display_name) { $data['attr_display_name'] = $display_name; } if ($form_type) { $data['form_type'] = $form_type; } if ($form_data) { $data['form_data'] = $form_data; } if ($attr_default) { $data['attr_default'] = $attr_default; } try { $property_attribute = sw_member::property_factory('madapter_attribute', $data); $condition = sw_member::condition_factory('mod_madapter_attribute', array('madapter_id' => $mid, 'attr_id' => $aid)); $condition->set_in('madapter_id'); $condition->set_in('attr_id'); $condition->set_property($property_attribute); $madapter = sw_member::operator_factory('madapter'); $madapter->get_operator('attribute')->mod_attribute($condition); } catch (\swan\exception\sw_exception $e) { return $this->render_json(null, 10002, $e->getMessage()); } return $this->render_json(null, 10000, 'mod madapter success.'); }
/** * test_mod_metric * * @access public * @return void */ public function test_mod_metric() { $data = array('time_threshold' => 1000, 'tmax' => 300, 'vmax' => '300'); $property_metric = sw_member::property_factory('madapter_metric', $data); $condition = sw_member::condition_factory('mod_madapter_metric', array('metric_id' => 1, 'madapter_id' => 1)); $condition->set_property($property_metric); $condition->set_in('madapter_id'); $condition->set_in('metric_id'); $madapter = sw_member::operator_factory('madapter'); $madapter->get_operator('metric')->mod_metric($condition); $query_table = $this->getConnection()->CreateQueryTable('madapter_metric', 'select * from madapter_metric'); $expect = $this->createXMLDataSet(dirname(__FILE__) . '/_files/mod_result.xml')->getTable('madapter_metric'); $this->assertTablesEqual($expect, $query_table); }
/** * test_mod_attribute * * @access public * @return void */ public function test_mod_attribute() { $data = array('attr_name' => 'url_b', 'attr_display_name' => 'URL B 地址'); $property_attribute = sw_member::property_factory('madapter_attribute', $data); $condition = sw_member::condition_factory('mod_madapter_attribute', array('attr_id' => 2, 'madapter_id' => 1)); $condition->set_property($property_attribute); $condition->set_in('madapter_id'); $condition->set_in('attr_id'); $madapter = sw_member::operator_factory('madapter'); $madapter->get_operator('attribute')->mod_attribute($condition); $query_table = $this->getConnection()->CreateQueryTable('madapter_attribute', 'select * from madapter_attribute'); $expect = $this->createXMLDataSet(dirname(__FILE__) . '/_files/mod_result.xml')->getTable('madapter_attribute'); $this->assertTablesEqual($expect, $query_table); }
/** * 修改监控适配器数据项 * * @access public * @return void */ public function action_mod() { $mid = $this->__request->get_post('madapter_id', ''); $arid = $this->__request->get_post('archive_id', ''); $cf_type = $this->__request->get_post('cf_type', ''); $xff = $this->__request->get_post('xff', ''); $title = $this->__request->get_post('title', ''); $steps = $this->__request->get_post('steps', ''); $rows = $this->__request->get_post('rows', ''); if (!$mid || !$arid) { return $this->render_json(null, 10001, '`mid` and `arid` not allow is empty.'); } // 修改 madapter archive $data = array(); if ($cf_type) { $data['cf_type'] = $cf_type; } if ($xff) { $data['xff'] = $xff; } if ($title) { $data['title'] = $title; } if ($steps) { $data['steps'] = $steps; } if ($rows) { $data['rows'] = $rows; } try { $property_archive = sw_member::property_factory('madapter_archive', $data); $condition = sw_member::condition_factory('mod_madapter_archive', array('madapter_id' => $mid, 'archive_id' => $arid)); $condition->set_in('madapter_id'); $condition->set_in('archive_id'); $condition->set_property($property_archive); $madapter = sw_member::operator_factory('madapter'); $madapter->get_operator('archive')->mod_archive($condition); } catch (\swan\exception\sw_exception $e) { return $this->render_json(null, 10002, $e->getMessage()); } return $this->render_json(null, 10000, 'mod madapter archive success.'); }
/** * 修改设备监控器 * * @access public * @return void */ public function action_mod() { $device_id = $this->__request->get_post('device_id', ''); $monitor_id = $this->__request->get_post('monitor_id', ''); $attr_data = $this->__request->get_post('attr_data', '{}'); if (!$device_id || !$monitor_id) { return $this->render_json(null, 10001, '`device_id`/`monitor_id` not allow is empty.'); } $attr_data = json_decode($attr_data, true); $monitor_params = array(); foreach ($attr_data as $value) { if (!isset($value['attr_id']) || !isset($value['value'])) { return $this->render_json(null, 10001, 'attr_data is must defined `attr_id`/`value` not allow is empty.'); } $monitor_params[] = sw_member::property_factory('madapter_params', array('attr_id' => $value['attr_id'], 'value' => $value['value'])); } // 修改 device monitor try { $device_property_key = sw_member::property_factory('device_key', array('device_id' => $device_id)); $device_property_monitor = sw_member::property_factory('device_monitor'); $device_property_monitor->set_monitor_params($monitor_params); $device_property_monitor->set_monitor_id($monitor_id); $device_property_monitor->set_in('monitor_id'); $condition = sw_member::condition_factory('mod_device_monitor'); $condition->set_property($device_property_monitor); $device = sw_member::operator_factory('device', $device_property_key); $device_monitor = $device->get_operator('monitor')->mod_monitor($condition); } catch (\swan\exception\sw_exception $e) { return $this->render_json(null, 10002, $e->getMessage()); } return $this->render_json(null, 10000, 'mod device monitor success.'); }
/** * test_mod_basic * * @access public * @return void */ public function test_mod_basic() { $data = array('device_display_name' => 'desc_lan-116', 'host_name' => '192.168.2.116', 'heartbeat_time' => 350); $property_basic = sw_member::property_factory('device_basic', $data); $condition = sw_member::condition_factory('mod_device_basic', array('device_id' => 2)); $condition->set_property($property_basic); $condition->set_in('device_id'); $device = sw_member::operator_factory('device'); $device->get_operator('basic')->mod_basic($condition); $query_table = $this->getConnection()->CreateQueryTable('device_basic', 'select * from device_basic'); $expect = $this->createXMLDataSet(dirname(__FILE__) . '/_files/mod_result.xml')->getTable('device_basic'); $this->assertTablesEqual($expect, $query_table); }
/** * 修改设备 * * @access public * @return void */ public function action_mod() { $did = $this->__request->get_post('device_id', ''); $host_name = $this->__request->get_post('host_name', ''); $heartbeat = $this->__request->get_post('heartbeat_time', ''); $display_name = $this->__request->get_post('display_name', ''); if (!$did) { return $this->render_json(null, 10001, '`device_id` not allow is empty.'); } if ($host_name) { $data['host_name'] = $host_name; } if ($display_name) { $data['device_display_name'] = $display_name; } if ($heartbeat) { $data['heartbeat_time'] = $heartbeat; } // 修改 device basic try { $property_basic = sw_member::property_factory('device_basic', $data); $condition = sw_member::condition_factory('mod_device_basic', array('device_id' => $did)); $condition->set_in('device_id'); $condition->set_property($property_basic); $device = sw_member::operator_factory('device'); $device->get_operator('basic')->mod_basic($condition); } catch (\swan\exception\sw_exception $e) { return $this->render_json(null, 10002, $e->getMessage()); } return $this->render_json(null, 10000, 'mod device success.'); }
/** * test_del_monitor * * @access public * @return void */ public function test_del_monitor() { $device_property_key = sw_member::property_factory('device_key', array('device_id' => '1')); $condition = sw_member::condition_factory('del_device_monitor'); $condition->set_in('monitor_id'); $condition->set_monitor_id(1); $device = sw_member::operator_factory('device', $device_property_key); $device->get_operator('monitor')->del_monitor($condition); $query_table = $this->getConnection()->CreateQueryTable('device_monitor', 'select * from device_monitor'); $expect = $this->createXMLDataSet(dirname(__FILE__) . '/_files/del_result.xml')->getTable('device_monitor'); $this->assertTablesEqual($expect, $query_table); $query_params = $this->getConnection()->CreateQueryTable('device_monitor_params', 'select * from device_monitor_params'); $expect_params = $this->createXMLDataSet(dirname(__FILE__) . '/_files/del_result.xml')->getTable('device_monitor_params'); $this->assertTablesEqual($expect_params, $query_params); }