1#!/usr/bin/env bash
2#
3# config: 123 30
4# @brief: Collect network information
5#
6
7# shellcheck disable=SC1091
8. "$DREPORT_INCLUDE"/functions
9
10file_name="network.log"
11
12#ip addr
13add_cmd_output "echo $'[ip addr]'" "$file_name" "ip addr"
14add_cmd_output "ip addr" "$file_name" "ip addr"
15
16#netstat
17add_cmd_output "echo $'\n[netstat]'" "$file_name" "netstat"
18add_cmd_output "netstat -nr" "$file_name" "netstat"
19
20#eth0
21eth0_file="/etc/systemd/network/00-bmc-eth0.network"
22if [ -f $eth0_file ]; then
23    add_cmd_output "echo $'\n[eth0]'" "$file_name" "eth0"
24    add_cmd_output "cat $eth0_file" "$file_name" "eth0"
25fi
26
27#eth1
28eth1_file="/etc/systemd/network/00-bmc-eth1.network"
29if [ -f $eth1_file ]; then
30    add_cmd_output "echo $'\n[eth1]'" "$file_name" "eth1"
31    add_cmd_output "cat $eth1_file" "$file_name" "eth1"
32fi
33
34
35#network interface statistics
36procnetdev_file="/proc/net/dev"
37if [ -f $procnetdev_file ]; then
38    add_cmd_output "echo $'\n[proc_net_dev]'" "$file_name" "proc_net_dev"
39    add_cmd_output "cat $procnetdev_file" "$file_name" "proc_net_dev"
40fi
41
42#active tcp connections
43activetcp="/proc/net/tcp"
44if [ -f $activetcp ]; then
45    add_cmd_output "echo $'\n[activetcp]'" "$file_name" "active tcp"
46    add_cmd_output "cat $activetcp" "$file_name" "active tcp"
47fi
48
49#Load average
50loadavg="/proc/loadavg"
51if [ -f $loadavg ]; then
52    add_cmd_output "echo $'\n[Load average]'" "$file_name" "load average"
53    add_cmd_output "cat $loadavg" "$file_name" "load average"
54fi
55