From 52dd5894a08d903988068af093adb40df4673e48 Mon Sep 17 00:00:00 2001 From: wangjianhua Date: Wed, 14 Sep 2022 23:06:12 +0800 Subject: [PATCH] * Register host on ZAgent server. --- module/zahost/lang/zh-cn.php | 5 +++-- module/zahost/model.php | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) 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';