zl程序教程

您现在的位置是:首页 >  系统

当前栏目

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