The cacti server deployed by the company is used to monitor network card traffic of all servers and add scripts in batches.
#! /Bin/bash # Add host for cactipath =/var/www/html/cacti/cliphp =/usr/bin/phpdevice = $ path/add_device.phpgraphs = $ path/add_graphs.phptree = $ path /add_tree.phpcommunity_name = xxxxxxcat. /hosts | while read host; dohost_ip = 'echo $ host | awk '{print $1} ''host _ name = 'echo $ host | awk' {print $2} ''#3 UCD/NET SNMP host $ PHP $ device -- Description = "$ host_name" -- IP = "$ host_ip" -- template = 3 -- version = 2 -- community = "$ community_name" host_ids = '$ PHP $ graphs -- list-hosts | grep $ host_ip | awk '{print $1} ''#16 in/out bytes networks = 'snmpwalk-V 2C-C $ community_name $ host_ip ifdesc | awk '{print $6}' | grep ^ ETH [0-9] $ 'for network in $ networks; do $ PHP $ graphs -- Host-id = "$ host_ids" -- Graph-type = DS -- Graph-template-id = 2 -- SNMP-query-id = 1 -- SNMP-Query -type-id = 16 -- SNMP-field = ifdescr -- SNMP-value = "$ network" done $ PHP $ graphs -- Host-id = "$ host_ids" -- Graph-type = DS -- Graph-template-id = 2 -- SNMP-query-id = 1 -- SNMP-query-type-id = 16 -- SNMP-field = ifdescr -- SNMP-value = "Lo "# Add devices to the corresponding group # default tree (built-in) -- tree-id = 1. You need to create a web program and view its tree ID: PHP add_tree.php -- list-trees $ PHP $ tree -- Host-id = "$ host_ids" -- type = node -- node-type = host -- tree-id = 1 done
This article is from the blog of the "Bremen band" and will not be reposted!