Skip to content

Commit

Permalink
zabbix_agent 初始化
Browse files Browse the repository at this point in the history
  • Loading branch information
midoks committed Jul 16, 2024
1 parent 492ac0b commit 03c5191
Show file tree
Hide file tree
Showing 12 changed files with 462 additions and 26 deletions.
1 change: 1 addition & 0 deletions plugins/zabbix/ico.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 0 additions & 22 deletions plugins/zabbix/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,6 @@ def checkArgs(data, ck=[]):
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!'))
return (True, mw.returnJson(True, 'ok'))

def configTpl():
path = getPluginDir() + '/tpl'
pathFile = os.listdir(path)
tmp = []
for one in pathFile:
file = path + '/' + one
tmp.append(file)
return mw.getJson(tmp)


def readConfigTpl():
args = getArgs()
data = checkArgs(args, ['file'])
if not data[0]:
return data[1]

content = mw.readFile(args['file'])
content = contentReplace(content)
return mw.returnJson(True, 'ok', content)

def getPidFile():
file = getConf()
content = mw.readFile(file)
Expand Down Expand Up @@ -329,7 +309,5 @@ def uninstallPreInspection():
print(zabbixServerConf())
elif func == 'run_log':
print(runLog())
elif func == 'config_tpl':
print(configTpl())
else:
print('error')
7 changes: 3 additions & 4 deletions plugins/zabbix/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/homebrew/bin
export PATH

# https://www.mongodb.com/try/download/community
# https://www.zabbix.com

# cd /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/mongodb && /bin/bash install.sh install 7.0
# cd /www/server/mdserver-web/plugins/mongodb && /bin/bash install.sh install 7.0
# cd /www/server/mdserver-web && python3 /www/server/mdserver-web/plugins/mongodb/index.py start
# cd /www/server/mdserver-web/plugins/zabbix && /bin/bash install.sh install 7.0
# cd /www/server/mdserver-web && python3 /www/server/mdserver-web/plugins/zabbix/index.py start



Expand Down
10 changes: 10 additions & 0 deletions plugins/zabbix_agent/conf/zabbix_server.conf
Original file line number Diff line number Diff line change
@@ -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
Binary file added plugins/zabbix_agent/ico.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions plugins/zabbix_agent/ico.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions plugins/zabbix_agent/index.html
Original file line number Diff line number Diff line change
@@ -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>
217 changes: 217 additions & 0 deletions plugins/zabbix_agent/index.py
Original file line number Diff line number Diff line change
@@ -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')
18 changes: 18 additions & 0 deletions plugins/zabbix_agent/info.json
Original file line number Diff line number Diff line change
@@ -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"
}
Loading

0 comments on commit 03c5191

Please sign in to comment.