mirror of https://github.com/midoks/mdserver-web
parent
492ac0bb60
commit
03c5191e89
After Width: | Height: | Size: 246 B |
@ -0,0 +1,10 @@ |
||||
LogFile=/var/log/zabbix/zabbix_server.log |
||||
LogFileSize=1 |
||||
PidFile=/run/zabbix/zabbix_server.pid |
||||
SocketDir=/run/zabbix |
||||
DBHost=127.0.0.1 |
||||
DBPort={$ZABBIX_DB_PORT} |
||||
DBName=zabbix |
||||
DBUser=zabbix |
||||
DBPassword={$ZABBIX_DB_PASS} |
||||
ListenPort=10051 |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 246 B |
@ -0,0 +1,30 @@ |
||||
<style> |
||||
.overflow_hide { |
||||
overflow: hidden; |
||||
text-overflow: ellipsis; |
||||
white-space: nowrap; |
||||
vertical-align: middle; |
||||
} |
||||
</style> |
||||
|
||||
<div class="bt-form"> |
||||
<div class='plugin_version'></div> |
||||
<div class="bt-w-main"> |
||||
<div class="bt-w-menu"> |
||||
<p class="bgw" onclick="pluginService('zabbix_agent');">服务</p> |
||||
<p onclick="pluginInitD('zabbix_agent');">自启动</p> |
||||
<p onclick="pluginConfig('zabbix_agent',$('.plugin_version').attr('version'),'zabbix_server_conf');">ZA配置</p> |
||||
<p onclick="pluginLogs('zabbix_agent','','run_log');">运行日志</p> |
||||
<p onclick="zabbixReadme();">相关说明</p> |
||||
|
||||
</div> |
||||
<div class="bt-w-con pd15"> |
||||
<div class="soft-man-con" style="height: 520px; overflow: auto;"></div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<script type="text/javascript"> |
||||
$.getScript( "/plugins/file?name=zabbix_agent&f=js/zabbix.js", function(){ |
||||
pluginService('zabbix_agent', $('.plugin_version').attr('version')); |
||||
}); |
||||
</script> |
@ -0,0 +1,217 @@ |
||||
# coding:utf-8 |
||||
|
||||
import sys |
||||
import io |
||||
import os |
||||
import time |
||||
import re |
||||
|
||||
sys.path.append(os.getcwd() + "/class/core") |
||||
import mw |
||||
|
||||
app_debug = False |
||||
if mw.isAppleSystem(): |
||||
app_debug = True |
||||
|
||||
|
||||
def getPluginName(): |
||||
return 'zabbix_agent' |
||||
|
||||
|
||||
def getPluginDir(): |
||||
return mw.getPluginDir() + '/' + getPluginName() |
||||
|
||||
|
||||
def getServerDir(): |
||||
return mw.getServerDir() + '/' + getPluginName() |
||||
|
||||
|
||||
def getInitDFile(): |
||||
current_os = mw.getOs() |
||||
if current_os == 'darwin': |
||||
return '/tmp/' + getPluginName() |
||||
return '/etc/init.d/' + getPluginName() |
||||
|
||||
|
||||
def getInitDTpl(): |
||||
path = getPluginDir() + "/init.d/" + getPluginName() + ".tpl" |
||||
return path |
||||
|
||||
|
||||
def getArgs(): |
||||
args = sys.argv[3:] |
||||
tmp = {} |
||||
args_len = len(args) |
||||
|
||||
if args_len == 1: |
||||
t = args[0].strip('{').strip('}') |
||||
if t.strip() == '': |
||||
tmp = [] |
||||
else: |
||||
t = t.split(':') |
||||
tmp[t[0]] = t[1] |
||||
tmp[t[0]] = t[1] |
||||
elif args_len > 1: |
||||
for i in range(len(args)): |
||||
t = args[i].split(':') |
||||
tmp[t[0]] = t[1] |
||||
return tmp |
||||
|
||||
def checkArgs(data, ck=[]): |
||||
for i in range(len(ck)): |
||||
if not ck[i] in data: |
||||
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!')) |
||||
return (True, mw.returnJson(True, 'ok')) |
||||
|
||||
def getPidFile(): |
||||
file = getConf() |
||||
content = mw.readFile(file) |
||||
rep = 'pidfile\s*(.*)' |
||||
tmp = re.search(rep, content) |
||||
return tmp.groups()[0].strip() |
||||
|
||||
def status(): |
||||
cmd = "ps aux|grep zabbix-agent |grep -v grep | grep -v python | grep -v mdserver-web | awk '{print $2}'" |
||||
data = mw.execShell(cmd) |
||||
if data[0] == '': |
||||
return 'stop' |
||||
return 'start' |
||||
|
||||
def contentReplace(content): |
||||
service_path = mw.getServerDir() |
||||
content = content.replace('{$ROOT_PATH}', mw.getRootDir()) |
||||
content = content.replace('{$SERVER_PATH}', service_path) |
||||
return content |
||||
|
||||
def zabbixAgentConf(): |
||||
return '/etc/zabbix/zabbix_server.conf' |
||||
|
||||
|
||||
def initOpConf(): |
||||
nginx_src_tpl = getPluginDir()+'/conf/zabbix.nginx.conf' |
||||
nginx_dst_vhost = zabbixNginxConf() |
||||
|
||||
# nginx配置 |
||||
if not os.path.exists(nginx_dst_vhost): |
||||
content = mw.readFile(nginx_src_tpl) |
||||
content = contentReplace(content) |
||||
mw.writeFile(nginx_dst_vhost, content) |
||||
|
||||
def initZsConf(): |
||||
zs_src_tpl = getPluginDir()+'/conf/zabbix_server.conf' |
||||
zs_dst_path = zabbixServerConf() |
||||
|
||||
# zabbix_server配置 |
||||
content = mw.readFile(zs_src_tpl) |
||||
content = contentReplace(content) |
||||
mw.writeFile(zs_dst_path, content) |
||||
|
||||
def initDreplace(): |
||||
|
||||
# initZsConf() |
||||
return True |
||||
|
||||
|
||||
def zOp(method): |
||||
|
||||
initDreplace() |
||||
|
||||
data = mw.execShell('systemctl ' + method + ' zabbix-agent') |
||||
if data[1] == '': |
||||
return 'ok' |
||||
return data[1] |
||||
|
||||
|
||||
def start(): |
||||
return zOp('start') |
||||
|
||||
|
||||
def stop(): |
||||
val = zOp('stop') |
||||
return val |
||||
|
||||
def restart(): |
||||
status = zOp('restart') |
||||
return status |
||||
|
||||
def reload(): |
||||
return zOp('reload') |
||||
|
||||
def initdStatus(): |
||||
current_os = mw.getOs() |
||||
if current_os == 'darwin': |
||||
return "Apple Computer does not support" |
||||
|
||||
shell_cmd = 'systemctl status zabbix-agent | grep loaded | grep "enabled;"' |
||||
data = mw.execShell(shell_cmd) |
||||
if data[0] == '': |
||||
return 'fail' |
||||
return 'ok' |
||||
|
||||
|
||||
def initdInstall(): |
||||
current_os = mw.getOs() |
||||
if current_os == 'darwin': |
||||
return "Apple Computer does not support" |
||||
|
||||
mw.execShell('systemctl enable zabbix-agent') |
||||
return 'ok' |
||||
|
||||
|
||||
def initdUinstall(): |
||||
current_os = mw.getOs() |
||||
if current_os == 'darwin': |
||||
return "Apple Computer does not support" |
||||
|
||||
mw.execShell('systemctl disable zabbix-agent') |
||||
return 'ok' |
||||
|
||||
|
||||
def installPreInspection(): |
||||
openresty_dir = mw.getServerDir() + "/openresty" |
||||
if not os.path.exists(openresty_dir): |
||||
return '需要安装Openresty插件' |
||||
|
||||
mysql_dir = mw.getServerDir() + "/mysql" |
||||
if not os.path.exists(mysql_dir): |
||||
return '需要安装MySQL插件,至少8.0!' |
||||
|
||||
return 'ok' |
||||
|
||||
|
||||
def uninstallPreInspection(): |
||||
return 'ok' |
||||
|
||||
|
||||
if __name__ == "__main__": |
||||
func = sys.argv[1] |
||||
if func == 'status': |
||||
print(status()) |
||||
elif func == 'start': |
||||
print(start()) |
||||
elif func == 'stop': |
||||
print(stop()) |
||||
elif func == 'restart': |
||||
print(restart()) |
||||
elif func == 'reload': |
||||
print(reload()) |
||||
elif func == 'initd_status': |
||||
print(initdStatus()) |
||||
elif func == 'initd_install': |
||||
print(initdInstall()) |
||||
elif func == 'initd_uninstall': |
||||
print(initdUinstall()) |
||||
elif func == 'install_pre_inspection': |
||||
print(installPreInspection()) |
||||
elif func == 'uninstall_pre_inspection': |
||||
print(uninstallPreInspection()) |
||||
elif func == 'conf': |
||||
print(zabbixNginxConf()) |
||||
elif func == 'php_conf': |
||||
print(zabbixPhpConf()) |
||||
elif func == 'zabbix_server_conf': |
||||
print(zabbixServerConf()) |
||||
elif func == 'run_log': |
||||
print(runLog()) |
||||
else: |
||||
print('error') |
@ -0,0 +1,18 @@ |
||||
{ |
||||
"sort": 7, |
||||
"ps": "Zabbix被控服务器[<span style='color:red;'>开发中</span>]", |
||||
"name": "zabbix_agent", |
||||
"title": "Zabbix Agent", |
||||
"shell": "install.sh", |
||||
"versions":["7.0"], |
||||
"updates":["7.0"], |
||||
"tip": "soft", |
||||
"checks": "server/zabbix_agent", |
||||
"path": "server/zabbix_agent", |
||||
"display": 1, |
||||
"author": "midoks", |
||||
"date": "2022-07-14", |
||||
"home": "https://www.zabbix.com", |
||||
"type": 0, |
||||
"pid": "5" |
||||
} |
@ -0,0 +1,77 @@ |
||||
#!/bin/bash |
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/homebrew/bin |
||||
export PATH |
||||
|
||||
# https://www.zabbix.com |
||||
|
||||
# cd /www/server/mdserver-web/plugins/zabbix_agent && /bin/bash install.sh install 7.0 |
||||
# cd /www/server/mdserver-web && python3 /www/server/mdserver-web/plugins/zabbix_agent/index.py start |
||||
|
||||
|
||||
curPath=`pwd` |
||||
rootPath=$(dirname "$curPath") |
||||
rootPath=$(dirname "$rootPath") |
||||
serverPath=$(dirname "$rootPath") |
||||
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl |
||||
VERSION=$2 |
||||
|
||||
sysName=`uname` |
||||
echo "use system: ${sysName}" |
||||
|
||||
OSNAME=`bash ${rootPath}/scripts/getos.sh` |
||||
|
||||
if [ "" == "$OSNAME" ];then |
||||
OSNAME=`cat ${rootPath}/data/osname.pl` |
||||
fi |
||||
|
||||
if [ "macos" == "$OSNAME" ];then |
||||
echo "不支持Macox" |
||||
exit |
||||
fi |
||||
|
||||
if [ -f ${rootPath}/bin/activate ];then |
||||
source ${rootPath}/bin/activate |
||||
fi |
||||
|
||||
Install_App() |
||||
{ |
||||
echo '正在安装脚本文件...' |
||||
mkdir -p $serverPath/source/zabbix_agent |
||||
shell_file=${curPath}/versions/${VERSION}/${OSNAME}.sh |
||||
|
||||
if [ -f $shell_file ];then |
||||
bash -x $shell_file install |
||||
else |
||||
echo '不支持...' |
||||
exit 1 |
||||
fi |
||||
|
||||
if [ "$?" == "0" ];then |
||||
mkdir -p $serverPath/zabbix_agent |
||||
echo "${VERSION}" > $serverPath/zabbix_agent/version.pl |
||||
|
||||
#初始化 |
||||
cd ${rootPath} && python3 ${rootPath}/plugins/zabbix_agent/index.py start |
||||
cd ${rootPath} && python3 ${rootPath}/plugins/zabbix_agent/index.py initd_install |
||||
fi |
||||
|
||||
echo 'Zabbix安装完成' |
||||
} |
||||
|
||||
Uninstall_App() |
||||
{ |
||||
cd ${rootPath} && python3 ${rootPath}/plugins/zabbix_agent/index.py stop |
||||
cd ${rootPath} && python3 ${rootPath}/plugins/zabbix_agent/index.py initd_uninstall |
||||
|
||||
rm -rf $serverPath/zabbix_agent |
||||
rm -rf $serverPath/source/zabbix_agent |
||||
echo 'Zabbix卸载完成' |
||||
} |
||||
|
||||
action=$1 |
||||
if [ "${1}" == 'install' ];then |
||||
Install_App |
||||
else |
||||
Uninstall_App |
||||
fi |
@ -0,0 +1,64 @@ |
||||
function zabbixPost(method, version, args,callback){ |
||||
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); |
||||
|
||||
var req_data = {}; |
||||
req_data['name'] = 'zabbix'; |
||||
req_data['func'] = method; |
||||
req_data['version'] = version; |
||||
|
||||
if (typeof(args) == 'string'){ |
||||
req_data['args'] = JSON.stringify(toArrayObject(args)); |
||||
} else { |
||||
req_data['args'] = JSON.stringify(args); |
||||
} |
||||
|
||||
$.post('/plugins/run', req_data, function(data) { |
||||
layer.close(loadT); |
||||
if (!data.status){ |
||||
//错误展示10S
|
||||
layer.msg(data.msg,{icon:0,time:2000,shade: [10, '#000']}); |
||||
return; |
||||
} |
||||
|
||||
if(typeof(callback) == 'function'){ |
||||
callback(data); |
||||
} |
||||
},'json');
|
||||
} |
||||
|
||||
function zabbixPostCallbak(method, version, args,callback){ |
||||
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); |
||||
|
||||
var req_data = {}; |
||||
req_data['name'] = 'zabbix'; |
||||
req_data['func'] = method; |
||||
args['version'] = version; |
||||
|
||||
if (typeof(args) == 'string'){ |
||||
req_data['args'] = JSON.stringify(toArrayObject(args)); |
||||
} else { |
||||
req_data['args'] = JSON.stringify(args); |
||||
} |
||||
|
||||
$.post('/plugins/callback', req_data, function(data) { |
||||
layer.close(loadT); |
||||
if (!data.status){ |
||||
layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']}); |
||||
return; |
||||
} |
||||
|
||||
if(typeof(callback) == 'function'){ |
||||
callback(data); |
||||
} |
||||
},'json');
|
||||
} |
||||
|
||||
|
||||
function zabbixReadme(){ |
||||
var readme = '<ul class="help-info-text c7">'; |
||||
readme += '<li>默认配置OpenResty端口:18888</li>'; |
||||
readme += '</ul>'; |
||||
|
||||
$('.soft-man-con').html(readme);
|
||||
} |
||||
|
@ -0,0 +1,41 @@ |
||||
#!/bin/bash |
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin |
||||
export PATH |
||||
|
||||
curPath=`pwd` |
||||
rootPath=$(dirname "$curPath") |
||||
rootPath=$(dirname "$rootPath") |
||||
serverPath=$(dirname "$rootPath") |
||||
sourcePath=${serverPath}/source |
||||
sysName=`uname` |
||||
install_tmp=${rootPath}/tmp/mw_install.pl |
||||
|
||||
SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'` |
||||
|
||||
Install_App() |
||||
{ |
||||
mkdir -p $serverPath/source/zabbix |
||||
|
||||
ZABBIX_NAME=zabbix-release_7.0-2+debian12_all.deb |
||||
echo "wget -O $serverPath/source/zabbix/${ZABBIX_NAME} https://repo.zabbix.com/zabbix/7.0/debian/pool/main/z/zabbix-release/${ZABBIX_NAME}" |
||||
if [ ! -f $serverPath/source/zabbix/${ZABBIX_NAME} ];then |
||||
wget -O $serverPath/source/zabbix/${ZABBIX_NAME} https://repo.zabbix.com/zabbix/7.0/debian/pool/main/z/zabbix-release/${ZABBIX_NAME} |
||||
fi |
||||
|
||||
cd $serverPath/source/zabbix && dpkg -i zabbix-release_7.0-2+debian12_all.deb |
||||
apt update -y |
||||
|
||||
apt install -y zabbix-agent |
||||
} |
||||
|
||||
Uninstall_App() |
||||
{ |
||||
echo "卸载成功" |
||||
} |
||||
|
||||
action=${1} |
||||
if [ "${1}" == 'install' ];then |
||||
Install_App |
||||
else |
||||
Uninstall_App |
||||
fi |
Loading…
Reference in new issue