Linux Shell脚本之通过json判断应用程序内部运行状态
2023-09-14 09:01:02 时间
由于今晚就要更新包含这段代码的应用,有可能来不及修改,因此我只能重新修改一下先前写好的脚本,现将脚本展示如下:
# Name: getdata_gwservice.sh # Version: 1.0 # Visual Name(human readable format): get data from Web Service(GWService) # Shell Script Function: get data from Web Service with curl, data format is json # Author: Guodong Ding # Date: Thu Aug 20 09:56:26 CST 2015 # parameter is necessary [ ! -z "$1" ] || exit 1 # resolve "jq" command for parse json if [[ ! `which jq` ]]; then
[ $? -ne 0 ] echo "Trying install jq failed! ";echo "Trying install jq successfully! "
# why not execute a string as command? # curlcli="$curl -d \"$postdata\" $url 2 /dev/null" # make repeated cli to a function function curlcli() {
#echo {"errcode":"1","errmsg":{"Mysql":{"code":"0","msg":"OK"},"Memcache":{"code":"0","msg":"0"},"MQ":{"code":"0","msg":"OK"},"BS":{"code":"1","errmsg":"os与bs连接出.故障"},"Redis":{"code":"0","errmsg":"OK"}}}
# TODO # How to merge function totalstatus() and function total_error_status() into a function? function totalstatus() {
# why we need a return for this function ? because we will use "||" to determine result of CLI
# Name: getdata_gwservice.sh # Version: 2.0 # Visual Name(human readable format): get data from Web Service(GWService) for Zabbix monitoring # Shell Script Function: get data from Web Service with curl, data format is json # Author: Guodong Ding # Date: Thu Aug 20 09:56:26 CST 2015 # parameter is necessary [ ! -z "$1" ] || exit 1 # resolve "jq" command for parse json if [[ ! `which jq` ]]; then
[ $? -ne 0 ] echo "Trying install jq failed! ";echo "Trying install jq successfully! "
# why not execute a string as command? # curlcli="$curl -d \"$postdata\" $url 2 /dev/null" # make repeated cli to a function function curlcli() {
#echo {"errcode":"1","errmsg":{"Mysql":{"code":"0","msg":"OK"},"Memcatch":{"code":"0","msg":"0"},"MQ":{"code":"0","msg":"OK"},"BS":{"code":"1","errmsg":"os与bs连接出.故障"},"Redis":{"code":"0","errmsg":"OK"}}}
# Why we need a return for this function? because we will use "||" to determine result of CLI,
# By the way , "||" is depended on the result which returned with keyword "return",
# tested pass with return a numeric argument lager than 1 , such as 1001, 9003, etc
tag:Linux命令行解析json,Linux Shell解析json,Zabbix业务监控,Zabbix自定义用户参数,Zabbix API
--end--
本文出自 “通信,我的最爱” 博客,请务必保留此出处http://dgd2010.blog.51cto.com/1539422/1686475
相关文章
- 监控Linux服务器网站状态的SHELL脚本详解程序员
- Linux系统下实现虚拟IP地址配置(linux虚拟ip地址)
- Linux查看网络连接状态的操作步骤(linux查看连接情况)
- Linux安装系统:正确的分区方法(linux安装系统分区)
- 极速查看Linux下的网络带宽状态(查看网络带宽linux)
- Linux窗口最小化技巧分享(linux最小化窗口)
- 监控Linux磁盘状态:必须做到这样(linux监控磁盘)
- 压缩 WAR 文件:Linux 上的挑战(linux压缩war)
- 状态Linux下线程退出状态的检测(linux判断线程退出)
- 状态查看Linux防火墙状态:简单几步就能完成(查看linux防火墙)
- USB网卡在Linux系统下的安装与使用(usb网卡linux)
- 与优势Linux的分支与其强大的优势(linux的分支)
- Linux系统资源利用率分析(linux资源使用情况)
- Linux下进程状态的分类和特性详解(linux进程状态)
- 掌握Linux命令行下端口状态的方法(linux端口状态命令行)
- Linux 的性能监控软件推荐,帮你实时监测系统运行状态。(linux性能监控软件)
- Linux磁盘分区操作指南(磁盘分区linux)
- Linux系统下运行 Shell 脚本文件的技巧(linux下运行sh文件)
- 从头开始:使用Linux双系统启动菜单(linux双系统启动菜单)
- 监控Linux系统运行状态的监控与分析(linux运行状态)
- 器状态探索Linux:查看服务器状态(linux查看服务)
- 脚本编写Linux下的Shell脚本:提升工作效率(linux编写shell)
- Linux 中最常用的Shell:为你提供便捷生活(linux常用shell)
- Linux下轻松使用Shell:简单、便捷、强大(linux常用shell)
- Linux下快捷端口查询技巧(linux 端口 查询)
- 用sem Linux改变未来 —— 开启新的时代(sem linux)
- 提高Linux机器的启动时间(linux 启动时间)
- Linux 上查看服务器状态:一种快捷方便的方法(linux查看服务器状态)
- Linux探究CPU使用率:一窥究竟(linux查看cpu使用率)
- Linux下如何关闭网络连接(linux关闭连接)