Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The index of Shell crawling Linux system is reported through api

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Background

(1)。 In the process of system operation and maintenance, we will encounter customized system operation and multiple human configuration, personalized configuration belongs to private configuration and does not belong to the monitoring category of the monitoring platform, and abnormal problems in personalized indicators will lead to unpredictable problems and program running risks in the system; in view of this scenario, we will provide our own check system check script or agent to achieve the system guarantee purpose; the following is the system detection script

two。 The system collects actual combat scripts

#! / bin/bash# system information crawling script function current_date () {start_current_date= "`date" +% Y-%m-%d% H:%M:%S "`" echo ${start_current_date}} function init_logs () {log_dir= "/ chj/logs/" log_file= "/ chj/logs/pushData.log" if [- f ${log_file}] then echo ${log_file} else touch ${log_file } echo ${log_file} fi} # 1 Get the system ip address function getSysIp () {ipaddr=$ (/ bin/hostname-I) echo $ipaddr} # 2. Parse dns to check whether there is a valid dns;function getSysDns () {domain= "do.chj.cloud" if dig @ 172.21.2.10$ domain + short | grep'[0-9]'> / dev/null;then echo "True" else echo "False" fi} # 3. Get the system env environment variable function getSysEnv () {envfile=/etc/profile.d/chj-common.shif [- f $envfile] then env=$ (grep "RUNTIME_ENV=" $envfile | awk-F "=" {print $2}') echo $envelse echo "none" fi} # 4. Get the application name function getJavaName () {appname=$ (ps-ef | grep java | grep-v "grep" | head-1 | awk-F "- D"'{print $2}'| awk-F "="'{print $2}') echo $appname} # 5. Get the java application jvm parameter function getJavaInfo () {appinfo=$ (ps-ef | grep java | grep-v "grep" | head-1 | sed's / [[: space:]] /-/ g') echo "$appinfo"} # 6. Get the application port function getAppPort () {apppid=$ (ps-ef | grep java | grep-v "grep" | / bin/awk'{print $2}'| head-1) if [!-z "$apppid"] then appport=$ (netstat-tulpn | grep "$apppid" | awk-F ":"'{print $2}'| / bin/awk-F ""'{print $1}') echo "$appport" else echo "fi} # 7. Get the current connection tcpfunction getTcp () {tcp=$ (netstat-anplt | grep-v tcp6 | grep-v "127.0.0.1" | grep "ESTABLISHED" | sort | awk'! a [$5] + {print}'| awk'{print $5) $7}'| sed's / [[: space:]] /-/ g' | sed's /\ / g' | sed's else echo sed /\ / g' | sed sshdlash. If [!-n "tcp"] then echo "none" else echo $tcp | sed's / [[: space:] /, / g'fi} # 8. Check whether nat;function sysNat () {local timeout= "1" local target= "www.badu.com" local ret_code= `curl-I-s-- connect-timeout ${timeout} ${target}-w% {http_code} | tail-n1` if ["x$ret_code" = "x200"]; then echo "1" else echo "0" fi} # 9. Call dynamic upload API to send request data function reqDynamicData () {sysipaddr=$1sysdns=$2sysenv=$3appName=$4appjvm=$5appPort=$6conntcp=$7nat=$8fetchUrl= "http://ops.chj.cloud/dynamic/api/v1"/bin/curl" $fetchUrl "- X POST-H" Content-Type: application/json "- d" {\ "instance_ip\":\ "$sysipaddr\",\ "env\":\ "$sysenv\",\ "dns\":\ "$sysdns\",\ "appname\":\ "$ppName\",\ "appjvm\":\ "$appjvm\" \ "appport\":\ "$appPort\",\ "apptcp\":\ "$conntcp\",\ "nat\":\ "$nat\"} # 10. Send data function main () {ip= `getSysIp`dns = `getSysDns`env = `getSysEnv`name = `getJavaName`jvm = `getJavaInfo`port = `getAppPort`tcp = `getTcp`nat = `sysNat`reqDynamicData $ip $dns $env $name $port $tcp $natlog= `i nit_ logs`runTime _ date= `current _ date`echo "upload time: $runTime_date > > $log} main

3. Database field design

3.1Creating database sql CREATE TABLE `dynamic_ Check` (`id` int (11) NOT NULL AUTO_INCREMENT, `ip` varchar (92) COLLATE utf8mb4_bin DEFAULT NULL, `dns` varchar (128) COLLATE utf8mb4_bin DEFAULT NULL, `env` varchar (64) COLLATE utf8mb4_bin DEFAULT NULL, `appname` text COLLATE utf8mb4_bin, `appport` varchar (32) COLLATE utf8mb4_bin DEFAULT NULL, `appjvm` text COLLATE utf8mb4_bin, `conn_ tcp` text COLLATE utf8mb4_bin, `snat` varchar (32) COLLATE utf8mb4_bin DEFAULT NULL, `run_ time` datetime DEFAULT NULL PRIMARY KEY (`id`) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin 3.2. Database table structure +-+ | Field | Type | Null | Key | Default | Extra | +-+-+ -+ | id | int (11) | NO | PRI | NULL | auto_increment | | ip | varchar (92) | YES | | NULL | | dns | varchar | YES | | NULL | env | | | varchar (64) | YES | | NULL | appname | text | YES | | NULL | | appport | varchar (32) | YES | | NULL | | appjvm | text | YES | | NULL | | conn_tcp | text | YES | | NULL | | | | snat | varchar (32) | YES | | NULL | | run_time | datetime | YES | | NULL | | +-+-+ |

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report