/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params, $index = true) { ///应用组用户只可查看所在组的应用 $svr_pool_con = ""; if ($index == true && Yii::$app->user->getIdentity()->admin != 1) { $app_con = "svr_gid in (0"; $query = DcmdUserGroup::find()->andWhere(['uid' => Yii::$app->user->getId()])->asArray()->all(); if ($query) { foreach ($query as $item) { $app_con .= "," . $item['gid']; } } $app_con .= ")"; $query = DcmdApp::find()->where($app_con)->asArray()->all(); $svr_pool_con = "app_id in (0"; foreach ($query as $item) { $svr_pool_con .= "," . $item['app_id']; } $svr_pool_con .= ")"; } $query = DcmdServicePoolNode::find()->where($svr_pool_con)->orderBy('ip'); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => 20]]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'svr_pool_id' => $this->svr_pool_id, 'svr_id' => $this->svr_id, 'nid' => $this->nid, 'app_id' => $this->app_id, 'utime' => $this->utime, 'ctime' => $this->ctime, 'opr_uid' => $this->opr_uid]); $query->andFilterWhere(['like', 'ip', $this->ip]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params, $unuse = false) { $con_str = ""; if ($unuse) { $q = DcmdServicePoolNode::find()->asArray()->all(); $con_str = " ip not in(0"; foreach ($q as $item) { $con_str .= ",'" . $item['ip'] . "'"; } $con_str .= ")"; } $query = DcmdNode::find()->where($con_str)->orderBy('ip'); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => '20']]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['nid' => $this->nid, 'ngroup_id' => $this->ngroup_id, 'online_time' => $this->online_time, 'purchase_time' => $this->purchase_time, 'maintain_time' => $this->maintain_time, 'utime' => $this->utime, 'ctime' => $this->ctime, 'opr_uid' => $this->opr_uid]); $query->andFilterWhere(['like', 'ip', $this->ip])->andFilterWhere(['like', 'host', $this->host])->andFilterWhere(['like', 'sid', $this->sid])->andFilterWhere(['like', 'did', $this->did])->andFilterWhere(['like', 'os_type', $this->os_type])->andFilterWhere(['like', 'os_ver', $this->os_ver])->andFilterWhere(['like', 'bend_ip', $this->bend_ip])->andFilterWhere(['like', 'public_ip', $this->public_ip])->andFilterWhere(['like', 'mach_room', $this->mach_room])->andFilterWhere(['like', 'rack', $this->rack])->andFilterWhere(['like', 'seat', $this->seat])->andFilterWhere(['like', 'server_brand', $this->server_brand])->andFilterWhere(['like', 'server_model', $this->server_model])->andFilterWhere(['like', 'cpu', $this->cpu])->andFilterWhere(['like', 'memory', $this->memory])->andFilterWhere(['like', 'disk', $this->disk])->andFilterWhere(['like', 'maintain_fac', $this->maintain_fac])->andFilterWhere(['like', 'comment', $this->comment]); return $dataProvider; }
public function actionSelectServicePoolNode($task_id) { ///获取已有的设备ip $query = DcmdTaskNode::find()->andWhere(['task_id' => $task_id])->asArray()->all(); $exist_ips = array(); foreach ($query as $item) { array_push($exist_ips, $item['ip']); } $task_service_pool = DcmdTaskServicePool::find()->andWhere(['task_id' => $task_id])->asArray()->all(); $service_pool = array(); foreach ($task_service_pool as $item) { $node = array(); $node['svr_pool_id'] = $item['svr_pool_id']; $node['svr_pool'] = $item['svr_pool']; $node['ip'] = array(); $svr_pool_node = DcmdServicePoolNode::find()->andWhere(['svr_pool_id' => $item['svr_pool_id']])->asArray()->all(); foreach ($svr_pool_node as $ip) { if (array_key_exists($ip['ip'], $exist_ips)) { continue; } array_push($node['ip'], $ip['ip']); } array_push($service_pool, $node); } return $this->render('select_service_pool_node', ['service_pool' => $service_pool, 'task_id' => $task_id, 'task_name' => "task_name"]); }
/** * Finds the DcmdServicePoolNode model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return DcmdServicePoolNode the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = DcmdServicePoolNode::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionGetAppSvr($id) { $arr = array(); ///获取应用命令 $dcmd_app = $this->findModel($id); $arr['name'] = $dcmd_app->app_name; $arr['children'] = array(); ///获取应用 $query = DcmdService::find()->andWhere(['app_id' => $id])->asArray()->all(); foreach ($query as $item) { $svr = array(); $svr['name'] = $item['svr_name']; $svr['children'] = array(); ///获取应用池子 $pool = DcmdServicePool::find()->andWhere(['svr_id' => $item['svr_id']])->asArray()->all(); foreach ($pool as $p) { $svrp = array(); $svrp['name'] = $p['svr_pool']; $svrp['children'] = array(); ///获取节点 $node = DcmdServicePoolNode::find()->andWhere(['svr_pool_id' => $p['svr_pool_id']])->asArray()->all(); foreach ($node as $n) { array_push($svrp['children'], array('name' => $n['ip'])); } array_push($svr['children'], $svrp); } array_push($arr['children'], $svr); } return json_encode($arr); }
protected function getSvrPoolNode($id) { $query = DcmdServicePoolNode::find()->where(['svr_pool_id' => $id])->all(); $ips = ""; if ($query) { foreach ($query as $item) { $ips .= $item->ip . ";"; } } return $ips; }
/** * Updates an existing DcmdService model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); ///仅仅用户与该应用在同一个系统组才可以操作 $temp = DcmdApp::findOne($model['app_id']); $query = DcmdUserGroup::findOne(['uid' => Yii::$app->user->getId(), 'gid' => $temp['sa_gid']]); if ($query == NULL) { Yii::$app->getSession()->setFlash('success', NULL); Yii::$app->getSession()->setFlash('error', "对不起, 你没有权限!"); return $this->redirect(array('dcmd-service/view', 'id' => $id)); } if (Yii::$app->request->post()) { ///判断节点多池子 if (Yii::$app->request->post()['DcmdService']['node_multi_pool'] == 0) { ///节点不可为多池子 $ret = DcmdServicePoolNode::find()->andWhere(['svr_id' => $id])->asArray()->all(); $ips = array(); foreach ($ret as $item) { if (array_key_exists($item['ip'], $ips)) { Yii::$app->getSession()->setFlash('error', "多个池子存在该IP:" . $item['ip']); return $this->redirect(['dcmd-service/view', 'id' => $id]); } $ips[$item['ip']] = 1; } } $model->utime = date('Y-m-d H:i:s'); $model->opr_uid = Yii::$app->user->getId(); if ($model->load(Yii::$app->request->post()) && $model->save()) { $this->oprlog(2, "modify service:" . $model->svr_name); Yii::$app->getSession()->setFlash('success', '修改成功!'); return $this->redirect(['view', 'id' => $model->svr_id]); } $err_str = ""; foreach ($model->getErrors() as $k => $v) { $err_str .= $k . ":" . $v[0] . "<br>"; } Yii::$app->getSession()->setFlash('error', "修改失败:" . $err_str); } return $this->render('update', ['model' => $model]); }
public function actionAdd($task_id) { $task_id = Yii::$app->request->queryParams['task_id']; $svr_pool_array = array(); $query = DcmdTaskServicePool::find()->andWhere(['task_id' => $task_id])->asArray()->all(); foreach ($query as $item) { $svr_pool_array[$item['svr_pool_id']] = $item['svr_pool']; } if (Yii::$app->request->post() && array_key_exists('selection', Yii::$app->request->post())) { $ret_msg = ""; $query = DcmdCenter::findOne(['master' => 1]); if ($query) { list($host, $port) = explode(':', $query["host"]); var_dump(Yii::$app->request->post()); ///exit; $task_id = Yii::$app->request->post()['task_id']; $select = Yii::$app->request->post()['selection']; foreach ($select as $k => $v) { list($ip, $svr_pool_id) = explode(',', $v); $reply = execTaskCmd($host, $port, $task_id, Yii::$app->user->getId(), 6, NULL, $ip, NULL, $svr_pool_array[$svr_pool_id]); if ($reply->getState() == 0) { $ret_msg .= $ip . ":添加成功 "; } else { $ret_msg .= $ip . ":添加失败:" . $reply->getErr() . " "; } } } else { $ret_msg = "添加失败:无法获取Center!"; } Yii::$app->getSession()->setFlash('success', $ret_msg); } ///echo "==="; ////var_dump(Yii::$app->request->queryParams); ///获取已经存在池子及对应的ip $query = DcmdTaskNode::find()->andWhere(['task_id' => $task_id])->asArray()->all(); $exist_svr_pool_ip = array(); foreach ($query as $item) { if (array_key_exists($item['svr_pool'], $exist_svr_pool_ip)) { array_push($exist_svr_pool_ip[$item['svr_pool']], $item['ip']); } else { $exist_svr_pool_ip[$item['svr_pool']] = array($item['ip']); } } ///限制服务池子 $query_con = "(1 = 0)"; if (array_key_exists('DcmdServicePoolNodeSearch', Yii::$app->request->queryParams) && array_key_exists('svr_pool_id', Yii::$app->request->queryParams['DcmdServicePoolNodeSearch']) && Yii::$app->request->queryParams['DcmdServicePoolNodeSearch']['svr_pool_id'] != '') { $query_con .= " or (svr_pool_id = " . $Yii::$app->request->queryParams['DcmdServicePoolNodeSearch']['svr_pool_id'] . " and ip not in (0"; ///排除该服务池子对应的ip $svr_pool = $svr_pool_array($Yii::$app->request->queryParams['DcmdServicePoolNodeSearch']['svr_pool_id']); if (array_key_exists($svr_pool, $exist_svr_pool_ip)) { foreach ($exist_svr_pool_ip[$svr_pool] as $ip) { $query_con .= ",'" . $ip . "'"; } } $query_con .= "))"; } else { foreach ($svr_pool_array as $svr_pool_id => $svr_pool) { $query_con .= " or (svr_pool_id = " . $svr_pool_id . " and ip not in (0"; if (array_key_exists($svr_pool, $exist_svr_pool_ip)) { foreach ($exist_svr_pool_ip[$svr_pool] as $ip) { $query_con .= ",'" . $ip . "'"; } } $query_con .= "))"; } } ///echo $query_con;exit; ///排除已经存在的ip $query = DcmdServicePoolNode::find()->where($query_con); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => 50]]); $searchModel = new DcmdServicePoolNodeSearch(); $searchModel->load(Yii::$app->request->queryParams); return $this->render('add', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'task_id' => $task_id, 'svr_pool' => $svr_pool_array]); }
public function actionAppList($ip) { $ret_msg = '<table class="table table-striped table-bordered"><tbody>'; $ret_msg .= "<tr><td>产品</td><td>产品别名</td><td>服务</td><td>服务池</td></tr>"; $connection = Yii::$app->db; ///$command = $connection->createCommand('SELECT * FROM dcmd_app'); ///$posts = $command->queryAll(); //从服务池获取该机器对应的服务列表 $query = DcmdServicePoolNode::findAll(['ip' => $ip]); if ($query) { $svr_id = "dcmd_service_pool.svr_id in (0"; foreach ($query as $svr_node) { $svr_id .= "," . $svr_node->svr_id; } $svr_id .= ")"; $sql = "select dcmd_app.app_name, dcmd_app.app_id, dcmd_app.app_alias, dcmd_service.svr_name, dcmd_service.svr_id, dcmd_service_pool.svr_pool , dcmd_service_pool.svr_pool_id from dcmd_app inner join dcmd_service on dcmd_app.app_id = dcmd_service.app_id inner join dcmd_service_pool on dcmd_service.svr_id = dcmd_service_pool.svr_id where " . $svr_id; $command = $connection->createCommand($sql); $data = $command->queryAll(); if ($data) { foreach ($data as $k => $v) { $ret_msg .= "<tr><td><a href='index.php?r=dcmd-app/view&id=" . $v['app_id'] . "' target=_blank>" . $v['app_name'] . "</a></td>"; $ret_msg .= "<td>" . $v['app_alias'] . "</td>"; $ret_msg .= "<td><a href='index.php?r=dcmd-service/view&id=" . $v['svr_id'] . "' target=_blank>" . $v['svr_name'] . "</a></td>"; $ret_msg .= "<td><a href='index.php?r=dcmd-service-pool/view&id=" . $v['svr_pool_id'] . "' target=_blank>" . $v['svr_pool'] . "</a></td></tr>"; } } } $ret_msg .= "</tbody></table>"; echo $ret_msg; }