diff --git a/module/zahost/lang/zh-cn.php b/module/zahost/lang/zh-cn.php index 56a1563a9c..97039f4f5b 100644 --- a/module/zahost/lang/zh-cn.php +++ b/module/zahost/lang/zh-cn.php @@ -100,5 +100,6 @@ $lang->zahost->versionList['centos']['7'] = '7'; $lang->zahost->versionList['centos']['8'] = '8'; $lang->zahost->notice = new stdclass(); -$lang->zahost->notice->ip = '『%s』格式不正确!'; -$lang->zahost->notice->pingError = '无法连接!请检查IP地址、服务器进程和端口状态。'; +$lang->zahost->notice->ip = '『%s』格式不正确!'; +$lang->zahost->notice->pingError = '无法连接!请检查IP地址、服务器进程和端口状态。'; +$lang->zahost->notice->registerHostError = '向ZAgenteb服务器注册宿主机失败!'; diff --git a/module/zahost/model.php b/module/zahost/model.php index 644c6c32c1..2e662c9dec 100644 --- a/module/zahost/model.php +++ b/module/zahost/model.php @@ -53,6 +53,15 @@ class zahostModel extends model $this->dao->update(TABLE_ASSET)->data($hostInfo)->check('name', 'unique'); if(dao::isError()) return false; + $hostInfo->secret = md5(time()); + /* Register on ZAgent server. */ + $result = json_decode(commonModel::http("http://{$hostInfo->publicIP}:8086/api/v1/refreshSecret", array('Secret' => $hostInfo->secret), array(CURLOPT_CUSTOMREQUEST => 'POST'), array(), 'json')); + if(empty($result) || $result->code != 200) + { + dao::$errors['publicIP'][] = $this->lang->zahost->notice->registerHostError; + return false; + } + $assetInfo['name'] = $hostInfo->name; $assetInfo['type'] = 'zahost'; $assetInfo['status'] = 'normal';