/** * 扫描告警列表插入消息队列 */ public function actionAlarmFind() { $configs = SmsConfig::find()->all(); foreach ($configs as $config) { $phones = implode(',', array_filter($this->getPhoneNum($config->receivers))); if (empty($phones)) { continue; } $condition = $config->alarmCondition; $time = strtotime('-1 hour'); $ips = null; if ($config->sms_device_type == 0) { $query = DeviceAlarm::find(); } else { $query = WirelessDeviceAlarm::find(); } if (!empty($config->dev_ips)) { $ips = explode(',', $config->dev_ips); } $alarms = $query->where(['and', 'faultTime>=' . $time, 'recStatus=0'])->andWhere($condition)->andFilterWhere(['deviceIp' => $ips])->select(SmsTemplate::$template_fields)->asArray()->all(); $template = $this->getTemplate($config->smsTemplate_id); foreach ($alarms as $alarm) { $model = new SmsList(); $model->receivers = $phones; $model->content = strtr($template, $alarm); if (!$model->save()) { Yii::error(print_r($model->getErrors(), true), 'sms/find'); } } } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = WirelessDeviceAlarm::find(); $query->andWhere(['not', ["deviceId" => 0]]); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'deviceId' => $this->deviceId, 'alarmLevel' => $this->alarmLevel, 'alarmCategory' => $this->alarmCategory, 'faultTime' => $this->faultTime, 'recTime' => $this->recTime, 'recStatus' => $this->recStatus, 'ackTime' => $this->ackTime, 'ackStatus' => $this->ackStatus, 'somState' => $this->somState, 'defineType' => $this->defineType, 'customAlarmLevel' => $this->customAlarmLevel, 'update_time' => $this->update_time, 'specificId' => $this->specificId, 'originalType' => $this->originalType]); $query->andFilterWhere(['like', 'OID', $this->OID])->andFilterWhere(['like', 'originalTypeDesc', $this->originalTypeDesc])->andFilterWhere(['like', 'deviceIp', $this->deviceIp])->andFilterWhere(['like', 'deviceName', $this->deviceName])->andFilterWhere(['like', 'alarmLevelDesc', $this->alarmLevelDesc])->andFilterWhere(['like', 'alarmCategoryDesc', $this->alarmCategoryDesc])->andFilterWhere(['like', 'faultTimeDesc', $this->faultTimeDesc])->andFilterWhere(['like', 'recTimeDesc', $this->recTimeDesc])->andFilterWhere(['like', 'recStatusDesc', $this->recStatusDesc])->andFilterWhere(['like', 'recUserName', $this->recUserName])->andFilterWhere(['like', 'ackTimeDesc', $this->ackTimeDesc])->andFilterWhere(['like', 'ackStatusDesc', $this->ackStatusDesc])->andFilterWhere(['like', 'ackUserName', $this->ackUserName])->andFilterWhere(['like', 'alarmDesc', $this->alarmDesc])->andFilterWhere(['like', 'remark', $this->remark])->andFilterWhere(['like', 'eventName', $this->eventName])->andFilterWhere(['like', 'reason', $this->reason]); return $dataProvider; }
public function actionDetail($id) { $this->layout = '//main'; $model = $this->findModel($id); $perQuery = WirelessDeviceTaskSummary::find()->where(["and", ["devId" => $id], ["not", ["taskId" => [1, 5]]]])->orderBy("instId desc")->groupBy('taskId'); $lists = new ActiveDataProvider(['query' => $perQuery, 'pagination' => ["pageSize" => 10]]); $query = WirelessDeviceAlarm::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ["pageSize" => 10]]); $query->where(["deviceId" => $id])->orderBy("faultTime desc")->limit(5); $links = $nodes = $linkModels = []; $nodes[] = ["name" => $model->ip, "id" => $model->id]; $apProvider = null; if ($model->categoryId == 1003) { $query = WirelessDeviceAp::find()->where(["acDevId" => $id]); $apProvider = new ActiveDataProvider(["query" => $query, "pagination" => ["pageSize" => 10]]); } else { $linkModels = WirelessDeviceLink::find()->where(["or", ["leftDevice" => $id], ["rightDevice" => $id]])->all(); foreach ($linkModels as $link) { if ($link->leftDevice == $id) { $node = $link->right; } else { $node = $link->left; } if (!$node) { continue; } $nodes[] = ["name" => $node->ip, "id" => $node->id]; $links[] = ["source" => $model->ip, "target" => $node->ip, "weight" => 0.9]; $links[] = ["source" => $node->ip, "target" => $model->ip, "weight" => 1]; } } $interfaceQuery = WirelessDeviceTaskSummary::find()->where(["devId" => $id, "taskId" => [1, 5]])->orderBy("update_time desc")->groupBy("taskId,objIndex"); $interfaceProvider = new ActiveDataProvider(['query' => $interfaceQuery, 'pagination' => ["pageSize" => 10]]); return $this->render("detail_wlan", ['id' => $id, "model" => $model, "perflists" => $lists, "alarmProvider" => $dataProvider, "nodes" => $nodes, "links" => $links, "apProvider" => $apProvider, "ifProvider" => $interfaceProvider, 'linkModels' => $linkModels]); }
/** * Finds the DeviceAlarm model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return DeviceAlarm the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id, $type = null) { if ($type == 2 && ($model = WirelessDeviceAlarm::findOne($id)) !== null) { return $model; } elseif (($model = DeviceAlarm::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }