Commit 699515e5 authored by Peter Möller's avatar Peter Möller
Browse files

Properly working (a bunch of small fixes)

	modified:   host-monitor.sh
        Lots of small changes
parent 4bf48a0d
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
# Getting data for the host web.cs.lth.se" # Getting data for the host web.cs.lth.se"
# 2021-05-17/PM # 2021-05-17/PM
# Tested on:
# - macOS 10.15 “Catalina”
MONITOR_RESTAPI_URL=https://monitor.cs.lth.se/api/v1 MONITOR_RESTAPI_URL=https://monitor.cs.lth.se/api/v1
source /usr/local/bin/host-monitor.template source /usr/local/bin/host-monitor.template
...@@ -10,71 +13,85 @@ source /usr/local/bin/host-monitor.template ...@@ -10,71 +13,85 @@ source /usr/local/bin/host-monitor.template
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# sysinfo # sysinfo
# Operating System (OS='macOS 10.15.7 (build: 19H1030)'): # Operating System (OS='macOS 10.15.7 (build: 19H1030)'):
OS="macOS $(sw_vers -productVersion 2>/dev/null) (build: $(sw_vers -buildVersion 2>/dev/null))" OS="macOS $(/usr/bin/sw_vers -productVersion 2>/dev/null) (build: $(/usr/bin/sw_vers -buildVersion 2>/dev/null))"
BuildVersion="$(sw_vers -buildVersion 2>/dev/null)" BuildVersion="$(/usr/bin/sw_vers -buildVersion 2>/dev/null)"
DistroVer="$(sw_vers -buildVersion 2>/dev/null)" # DistroVer='20C69' DistroVer="$(/usr/bin/sw_vers -buildVersion 2>/dev/null)" # DistroVer='20C69'
# Get the OS version # Get the OS version
OSver="$(sw_vers -productVersion 2>/dev/null)" OSver="$(/usr/bin/sw_vers -productVersion 2>/dev/null)"
# Get a full name for the version (see https://en.wikipedia.org/wiki/Darwin_(operating_system)): # Get a full name for the version (see https://en.wikipedia.org/wiki/Darwin_(operating_system)):
case "$DistroVer" in case "$DistroVer" in
8*) Distro="Mac OS X ${OSver} Tiger (build: $BuildVersion)" ;; 8*) Distro="Mac OS X ${OSver} Tiger (build: $BuildVersion)" ;;
9*) Distro="Mac OS X ${OSver} Leopard (build: $BuildVersion)" ;; 9*) Distro="Mac OS X ${OSver} Leopard (build: $BuildVersion)" ;;
10*) Distro="Mac OS X ${OSver} Snow Leopard (build: $BuildVersion)" ;; 10*) Distro="Mac OS X ${OSver} Snow Leopard (build: $BuildVersion)" ;;
11*) Distro="Mac OS X ${OSver} Lion (build: $BuildVersion)" ;; 11*) Distro="Mac OS X ${OSver} Lion (build: $BuildVersion)" ;;
12*) Distro="OS X ${OSver} Mountain Lion (build: $BuildVersion)" ;; 12*) Distro="OS X ${OSver} Mountain Lion (build: $BuildVersion)" ;;
13*) Distro="OS X ${OSver} Mavericks (build: $BuildVersion)" ;; 13*) Distro="OS X ${OSver} Mavericks (build: $BuildVersion)" ;;
14*) Distro="OS X ${OSver} Yosemite (build: $BuildVersion)" ;; 14*) Distro="OS X ${OSver} Yosemite (build: $BuildVersion)" ;;
15*) Distro="OS X ${OSver} El Capitan (build: $BuildVersion)" ;; 15*) Distro="OS X ${OSver} El Capitan (build: $BuildVersion)" ;;
16*) Distro="macOS ${OSver} Sierra (build: $BuildVersion)" ;; 16*) Distro="macOS ${OSver} Sierra (build: $BuildVersion)" ;;
17*) Distro="macOS ${OSver} High Sierra (build: $BuildVersion)" ;; 17*) Distro="macOS ${OSver} High Sierra (build: $BuildVersion)" ;;
18*) Distro="macOS ${OSver} Mojave (build: $BuildVersion)" ;; 18*) Distro="macOS ${OSver} Mojave (build: $BuildVersion)" ;;
19*) Distro="macOS ${OSver} Catalina (build: $BuildVersion)" ;; 19*) Distro="macOS ${OSver} Catalina (build: $BuildVersion)" ;;
20*) Distro="macOS ${OSver} Big Sur (build: $BuildVersion)" ;; 20*) Distro="macOS ${OSver} Big Sur (build: $BuildVersion)" ;;
*) Distro="macOS" ;; *) Distro="macOS" ;;
esac esac
# Kind of CPU (CPUModel=CPUModel='Quad-Core Intel Core i3'): # Kind of CPU (CPUModel=CPUModel='Quad-Core Intel Core i3'):
SysHW="$(system_profiler SPHardwareDataType 2>/dev/null)" SysHW="$(/usr/sbin/system_profiler SPHardwareDataType 2>/dev/null)"
CPUModel="$(sysctl -n machdep.cpu.brand_string | sed -e 's/(R)/®/g' -e 's/(TM)/™/g')" CPUModel="$(/usr/sbin/sysctl -n machdep.cpu.brand_string | sed -e 's/(R)/®/g' -e 's/(TM)/™/g')"
# CPUModel='Intel® Core™ i3-8100B CPU @ 3.60GHz' or CPUModel='Apple M1' # CPUModel='Intel® Core™ i3-8100B CPU @ 3.60GHz' or CPUModel='Apple M1'
# Number of CPU:s (NbrCPUs=2): # Number of CPU:s (NbrCPUs=2):
NbrCPUs=$(sysctl hw.physicalcpu | awk '{print $NF}') NbrCPUs=$(/usr/sbin/sysctl hw.logicalcpu | awk '{print $NF}')
# Size of memory [kB] (# RAM=3997352): # Size of memory [kB] (# RAM=3997352):
RAM=$(echo "scale=0; $(sysctl hw.memsize | awk '{print $NF}') / 1024" | bc -l) RAM=$(echo "scale=0; $(/usr/sbin/sysctl hw.memsize | awk '{print $NF}') / 1024" | bc -l)
# Kind of memory (ECC='No ECC' or ECC='Multi-bit ECC'). No Mac's have ECC memory as of 2021: # Kind of memory (ECC='No ECC' or ECC='Multi-bit ECC'). No Mac's have ECC memory as of 2021:
ECC="No ECC" ECC="No ECC"
# What kind of authentication? Ex: Authentication=Lucat # What kind of authentication? Ex: Authentication=Lucat
Authentication="$(if [ "$(dsconfigad -show 2>/dev/null | grep "Active Directory Domain" | cut -d= -f2 | sed 's/^ *//')" = "uw.lu.se" ]; then echo "Lucat"; else echo "Standalone"; fi)" if [ "$(dsconfigad -show 2>/dev/null | grep "Active Directory Domain" | cut -d= -f2 | sed 's/^ *//')" = "uw.lu.se" ]; then
Authentication="Lucat"
else
Authentication="Standalone"
fi
AuthStr="\"authentication\": \"${Authentication}\"" # Ex: AuthStr='"authentication": "Lucat"' AuthStr="\"authentication\": \"${Authentication}\"" # Ex: AuthStr='"authentication": "Lucat"'
# Firewall. Ex: Firewall=ufw
Firewall=""
FirewWStr="\"firewall\":\"${Firewall}\"" # Ex: FirewWStr='"firewall":"ufw"'
# Disks # Disks
#Filesystems="$(df -kT -t xfs -t ext4 | egrep "\/" | awk '{print $1" "$2" "$3" "$7}')"
# Ex: a number of rows with
# Filesystem Type 1K-blocks Mounted on
#/dev/mapper/vg0-ubuntu ext4 13343816 /
PartList="$(df 2>/dev/null | egrep "^\/dev\/disk" | awk '{print $1}' | sort)" PartList="$(df 2>/dev/null | egrep "^\/dev\/disk" | awk '{print $1}' | sort)"
# Ex: PartList='/dev/disk1 /dev/disk2s3 /dev/disk3s3 /dev/disk3s2 /dev/disk2s2' # Ex: PartList='/dev/disk1 /dev/disk2s3 /dev/disk3s3 /dev/disk3s2 /dev/disk2s2'
# Flags # Flags
# SIP # SIP
[[ -x /usr/bin/csrutil ]] && SIP="$(csrutil status 2>/dev/null | cut -d: -f2 | sed -e 's/^\ //g' -e 's/.$//' | perl -pe 's/^(.)/uc($1)/e')" || SIP="Not enabled" if [ -x /usr/bin/csrutil ]; then
SIP="$(csrutil status 2>/dev/null | cut -d: -f2 | sed -e 's/^\ //g' -e 's/.$//' | perl -pe 's/^(.)/uc($1)/e')"
else
SIP="Not enabled"
fi
# ALF # ALF
ALF="$(/usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate | cut -d\. -f1 | awk '{print $NF}' | perl -pe 's/^(.)/uc($1)/e')" ALF="$(/usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate | cut -d\. -f1 | awk '{print $NF}' | perl -pe 's/^(.)/uc($1)/e')"
if [ "$ALF" = "Enabled" ]; then
Firewall="ALF"
else
Firewall=""
fi
# Packet Filter Firewall # Packet Filter Firewall
PFF="$(pfctl -sa 2>/dev/null | grep ^Status: | awk '{print $2}')" PFF="$(/sbin/pfctl -sa 2>/dev/null | grep ^Status: | awk '{print $2}')"
# FileVault # FileVault
FileVault="$(fdesetup status | grep "^FileVault is " | awk '{print $NF}' | sed 's/\.$//')" FileVault="$(/usr/bin/fdesetup status | grep "^FileVault is " | awk '{print $NF}' | sed 's/\.$//' | sed -e 's/On/Enabled/' -e 's/Off/Disabled/')"
# GateKeeper # GateKeeper
GateKeeper="$(spctl --status 2>/dev/null | awk '{print $2}' | perl -pe 's/^(.)/uc($1)/e')" GateKeeper="$(/usr/sbin/spctl --status 2>/dev/null | awk '{print $2}' | perl -pe 's/^(.)/uc($1)/e')"
# Little Snitch # Little Snitch
LittleSnitch="$(if [ -n "$(pgrep "littlesnitch.daemon")" ]; then echo "Running"; else echo "Not running"; fi)" if [ -n "$(pgrep "littlesnitch.daemon")" ]; then
LittleSnitch="Enabled"
else
if [ -x /Applications/Little\ Snitch.app/Contents/MacOS/Little\ Snitch ]; then
LittleSnitch="Disabled"
else
LittleSnitch="Not installed"
fi
fi
FirewWStr="\"firewall\":\"${Firewall}\"" # Ex: FirewWStr='"firewall":"ALF"'
# Ex: CPUBugs='cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit'
Architecture="$(uname -m 2>/dev/null | sed -e "s/i386/i686/")" # Ex: Architecture=arm64 Architecture="$(uname -m 2>/dev/null | sed -e "s/i386/i686/")" # Ex: Architecture=arm64
# Are we in a Virtual environment # Are we in a Virtual environment
MacModel="$(system_profiler SPHardwareDataType 2>/dev/null | egrep "^\s*Model Identifier:" | awk '{print $NF}')" MacModel="$(/usr/sbin/system_profiler SPHardwareDataType 2>/dev/null | egrep "^\s*Model Identifier:" | awk '{print $NF}')"
if [ ! "$(echo $MacModel | cut -c1-3)" = "Mac" -a ! "$(echo $MacModel | cut -c1-3)" = "iMa" -a ! "$(echo $MacModel | cut -c1-3)" = "Xse" ]; then if [ ! "$(echo $MacModel | cut -c1-3)" = "Mac" -a ! "$(echo $MacModel | cut -c1-3)" = "iMa" -a ! "$(echo $MacModel | cut -c1-3)" = "Xse" ]; then
VMenv="Virtual Mac" VMenv="Virtual Mac"
else else
...@@ -84,12 +101,12 @@ fi ...@@ -84,12 +101,12 @@ fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Security patches # Security patches
SecurityPatches="$(softwareupdate -l 2>/dev/null | egrep -i "Security" | cut -d: -f2 | cut -c2-)" SecurityPatches="$(/usr/sbin/softwareupdate -l 2>/dev/null | egrep -i "Security" | cut -d: -f2 | cut -c2-)"
# Ex: SecurityPatches='macOS Catalina Security Update 2021-003-10.15.7' # Ex: SecurityPatches='macOS Catalina Security Update 2021-003-10.15.7'
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Listening ports # Listening ports
ListeningPorts="$(lsof +c 0 -i 4 -i 6 -n -P 2>/dev/null | grep LISTEN | awk '{print $1" "$3" "$5" "$8" "$9 }' | sed 's/\(.*\):/\1 /' | sort -u)" ListeningPorts="$(/usr/sbin/lsof +c 0 -i 4 -i 6 -n -P 2>/dev/null | grep LISTEN | awk '{print $1" "$3" "$5" "$8" "$9 }' | sed 's/\(.*\):/\1 /' | sort -u)"
# List of: Application User IPver Proto Servicerange Port # List of: Application User IPver Proto Servicerange Port
# apache2 root IPv6 TCP * 88 # apache2 root IPv6 TCP * 88
# apache2 www-data IPv6 TCP * 88 # apache2 www-data IPv6 TCP * 88
...@@ -101,7 +118,7 @@ ListeningPorts="$(lsof +c 0 -i 4 -i 6 -n -P 2>/dev/null | grep LISTEN | awk '{pr ...@@ -101,7 +118,7 @@ ListeningPorts="$(lsof +c 0 -i 4 -i 6 -n -P 2>/dev/null | grep LISTEN | awk '{pr
# dsmcad root IPv4 TCP * 2123 # dsmcad root IPv4 TCP * 2123
# Network interfaces # Network interfaces
IFs="$(networksetup -listnetworkserviceorder 2>/dev/null | egrep "Hardware Port:" | awk '{print $NF}' | cut -d\) -f1)" IFs="$(/usr/sbin/networksetup -listnetworkserviceorder 2>/dev/null | egrep "Hardware Port:" | awk '{print $NF}' | cut -d\) -f1)"
# Ex: IFs='en0 # Ex: IFs='en0
# en1 # en1
# en7 # en7
...@@ -113,8 +130,6 @@ IFs="$(networksetup -listnetworkserviceorder 2>/dev/null | egrep "Hardware Port: ...@@ -113,8 +130,6 @@ IFs="$(networksetup -listnetworkserviceorder 2>/dev/null | egrep "Hardware Port:
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# sysinfo # sysinfo
# Create a string for the CPU Bugs (to make the final assemble shorter)
CPUBugsStr="$(if [ -n "$CPUBugs" ]; then echo ", \"cpu-bugs:${CPUBugs// /\", \"cpu-bugs:}\""; fi)"
# Platform # Platform
if [ -n "$VMenv" ]; then if [ -n "$VMenv" ]; then
PlatformStr="\"platform\": { \"virtualized\": true, \"name\": \"$VMenv\" }" PlatformStr="\"platform\": { \"virtualized\": true, \"name\": \"$VMenv\" }"
...@@ -123,32 +138,31 @@ else ...@@ -123,32 +138,31 @@ else
fi fi
# Assemble the Flags string # Assemble the Flags string
Flags="\"SIP:$SIP\", \"ALF:${ALF}\", \"PFF:$PFF\", \"FileVault:$FileVault\", \"GateKeeper:$GateKeeper\", \"LittleSnitch:$LittleSnitch\", \"vm:${VMenv}\", \"arch:${Architecture:---}\", \"selinux:N/A\"" Flags="\"SIP:$SIP\", \"ALF:${ALF}\", \"PFF:$PFF\", \"FileVault:$FileVault\", \"GateKeeper:$GateKeeper\", \"LittleSnitch:$LittleSnitch\", \"arch:${Architecture:---}\", \"selinux:N/A\""
# Ex: Flags='"selinux:Not present", "kernel:5.4.0-62-generic", "cpu-bugs:cpu_meltdown", "cpu-bugs:spectre_v1", "cpu-bugs:spectre_v2", "cpu-bugs:spec_store_bypass", "cpu-bugs:l1tf", "cpu-bugs:mds", "cpu-bugs:swapgs", "cpu-bugs:itlb_multihit", "vm:VMware Virtual Platform", "arch:x86_64"' # Ex: Flags='"SIP:Enabled", "ALF:Enabled", "PFF:Disabled", "FileVault:Off", "GateKeeper:Enabled", "LittleSnitch:Not running", "arch:x86_64", "selinux:N/A"'
# partitions # partitions
OUTPUT="" OUTPUT=""
while read -r Partition while read -r Partition
do do
MountPoint="$(df 2>/dev/null | grep "^$Partition" | cut -d% -f3 | sed 's/^ *//')" MountPoint="$(df 2>/dev/null | grep "^$Partition" | cut -d% -f3 | sed 's/^ *//')"
FS="$(diskutil info "$MountPoint" | grep "Name (User Visible):" | cut -d: -f2 | sed 's/^ *//')" FS="$(/usr/sbin/diskutil info "$MountPoint" | grep "Name (User Visible):" | cut -d: -f2 | sed 's/^ *//')"
TotalKb="$(df -lk | egrep "\s${MountPoint}$" | awk '{print $2}')" TotalKb="$(df -lk | egrep "\s${MountPoint}$" | awk '{print $2}')"
LVM="" LVM=""
OUTPUT+="{ \"partition\": \"$Partition\", \"mount-point\":\"$MountPoint\", \"type\":\"$FS\", \"total-kb\":$TotalKb, \"storage\":\"${LVM:-direct}\" }," OUTPUT+="{ \"partition\": \"$Partition\", \"mount-point\":\"$MountPoint\", \"type\":\"$FS\", \"total-kb\":$TotalKb, \"storage\":\"${LVM:-direct}\" },"
done <<< "$PartList" done <<< "$PartList"
# Eliminate the final comma
FilesystemStr="\"partitions\": [ ${OUTPUT%%,} ]" FilesystemStr="\"partitions\": [ ${OUTPUT%%,} ]"
# Network interfaces # Network interfaces
OUTPUT="" OUTPUT=""
for iname in $IFs for iname in $IFs
do do
if ifconfig $iname &>/dev/null; then if /sbin/ifconfig $iname &>/dev/null; then
IP4="$(ifconfig $iname | egrep "\sinet\s" | awk '{print $2}')" IP4="$(/sbin/ifconfig $iname | egrep "\sinet\s" | awk '{print $2}')"
IP6="$(ifconfig $iname | egrep "\sinet6\s" | awk '{print $2}')" IP6="$(/sbin/ifconfig $iname | egrep "\sinet6\s" | awk '{print $2}')"
MAC="$(ifconfig $iname | egrep "\sether\s" | awk '{print $2}')" MAC="$(/sbin/ifconfig $iname | egrep "\sether\s" | awk '{print $2}')"
MAC_P="N/A" MAC_P="N/A"
Speed="$(ifconfig $iname | egrep "\smedia:\s" | cut -d: -f2 | cut -c2-)" Speed="$(/sbin/ifconfig $iname | egrep "\smedia:\s" | cut -d: -f2 | cut -c2-)"
OUTPUT+="{ \"interface\": \"$iname\", \"ip4\": \"${IP4}\", \"ip6\": \"${IP6}\", \"mac\": \"${MAC}\", \"mac-p\": \"${MAC_P}\", \"speed\": \"${Speed}\" }," OUTPUT+="{ \"interface\": \"$iname\", \"ip4\": \"${IP4}\", \"ip6\": \"${IP6}\", \"mac\": \"${MAC}\", \"mac-p\": \"${MAC_P}\", \"speed\": \"${Speed}\" },"
fi fi
done done
...@@ -159,7 +173,7 @@ CPUstr="\"cpu\": { \"name\": \"${CPUModel:---}\", \"threads\": ${NbrCPUs:---} }" ...@@ -159,7 +173,7 @@ CPUstr="\"cpu\": { \"name\": \"${CPUModel:---}\", \"threads\": ${NbrCPUs:---} }"
RAMStr="\"memory\": { \"total-kb\": ${RAM:---}, \"type\": \"${ECC:---}\" }" RAMStr="\"memory\": { \"total-kb\": ${RAM:---}, \"type\": \"${ECC:---}\" }"
SysinfoStr="\"sysinfo\": { \"os\": \"${Distro:---}\", \"authentication\":\"${Authentication}\", \"firewall\":\"ALF: ${ALF}\", \"flags\": [ ${Flags} ], $CPUstr, $RAMStr, ${FilesystemStr}, $NIStr, $PlatformStr }" SysinfoStr="\"sysinfo\": { \"os\": \"${Distro:---}\", \"authentication\":\"${Authentication}\", \"firewall\":\"ALF: ${ALF}\", \"flags\": [ ${Flags} ], $CPUstr, $RAMStr, ${FilesystemStr}, $NIStr, $PlatformStr }"
# Ex: # Ex:
# SysinfoStr='"sysinfo": { "os": "Ubuntu 20.10", "authentication":"Lucat", "firewall":"ufw", "flags": [ "selinux:Not present", "kernel:5.4.0-62-generic", "cpu-bugs:cpu_meltdown", "cpu-bugs:spectre_v1", "cpu-bugs:spectre_v2", "cpu-bugs:spec_store_bypass", "cpu-bugs:l1tf", "cpu-bugs:mds", "cpu-bugs:swapgs", "cpu-bugs:itlb_multihit", "vm:VMware Virtual Platform", "arch:x86_64" ], "cpu": { "name": "Intel® Xeon® CPU E5-2680 v4 @ 2.40GHz", "threads": 2 }, "memory": { "total-kb": 2006416, "type": "No ECC" }, "partitions": [ { "partition": "/dev/mapper/vg0-ubuntu", "mount-point":"/", "type":"ext4", "total-kb":13343816, "lvm":"LVM" },{ "partition": "/dev/sda2", "mount-point":"/boot", "type":"ext4", "total-kb":999320, "lvm":"--" },{ "partition": "/dev/mapper/vg2-log", "mount-point":"/var/log", "type":"ext4", "total-kb":10251576, "lvm":"LVM" },{ "partition": "/dev/mapper/vg1-home", "mount-point":"/home", "type":"ext4", "total-kb":515795384, "lvm":"LVM" } ] }' # SysinfoStr='"sysinfo": { "os": "macOS 10.15.7 “Catalina” (build: 19H1030)", "authentication":"Lucat", "firewall":"ALF: Enabled", "flags": [ "SIP:Enabled", "ALF:Enabled", "PFF:Disabled", "FileVault:Off", "GateKeeper:Enabled", "LittleSnitch:Not running", "arch:x86_64", "selinux:N/A" ], "cpu": { "name": "Intel® Core™ i7-4578U CPU @ 3.00GHz", "threads": 2 }, "memory": { "total-kb": 16777216, "type": "No ECC" }, "partitions": [ { "partition": "/dev/disk1s1", "mount-point":"/System/Volumes/Data", "type":"APFS", "total-kb":244912536, "storage":"direct" },{ "partition": "/dev/disk1s3", "mount-point":"/Volumes/Recovery", "type":"APFS", "total-kb":244912536, "storage":"direct" },{ "partition": "/dev/disk1s4", "mount-point":"/private/var/vm", "type":"APFS", "total-kb":244912536, "storage":"direct" },{ "partition": "/dev/disk1s5", "mount-point":"/", "type":"APFS", "total-kb":244912536, "storage":"direct" } ], "network-interfaces": [ { "interface": "en0", "ip4": "130.235.16.21", "ip6": "fe80::58:8f2a:e921:f63e%en0", "mac": "ac:87:a3:06:ac:d9", "mac-p": "N/A", "speed": "autoselect (1000baseT <full-duplex,flow-control>)" },{ "interface": "en1", "ip4": "", "ip6": "", "mac": "6c:40:08:be:15:f8", "mac-p": "N/A", "speed": "autoselect (<unknown type>)" },{ "interface": "bridge0", "ip4": "", "ip6": "", "mac": "82:15:01:5d:58:40", "mac-p": "N/A", "speed": "<unknown type>" } ], "platform": { "virtualized": false, "name": "type:Macmini7,1" } }'
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# listening ports # listening ports
...@@ -170,15 +184,14 @@ if [ -n "$ListeningPorts" ]; then ...@@ -170,15 +184,14 @@ if [ -n "$ListeningPorts" ]; then
read Application User IPver Proto Binding Port <<< "$line" read Application User IPver Proto Binding Port <<< "$line"
# Determine if there's some form of firewall rule that covers $Port: # Determine if there's some form of firewall rule that covers $Port:
FWrule="null" FWrule="null"
OUTPUT+="{ \"binding\": \"${Binding:--}\", \"port\": ${Port:--}, \"process-owner\": \"${Application:--}\", \"process-user\": \"${User:--}\", \"protocol\": \"${Proto:--}\", \"firewall-rule\": $FWrule }," OUTPUT+="{ \"binding\": \"${Binding:--}\", \"port\": ${Port:--}, \"process-owner\": \"${Application:--}\", \"process-user\": \"${User:--}\", \"protocol\": \"${IPver}:${Proto:--}\", \"firewall-rule\": $FWrule },"
done <<< "$ListeningPorts" done <<< "$ListeningPorts"
# Eliminate the final comma
ListenStr=", \"listen-ports\": [ ${OUTPUT%%,} ]" ListenStr=", \"listen-ports\": [ ${OUTPUT%%,} ]"
else else
ListenStr="" ListenStr=""
fi fi
# Ex: # Ex:
# ListenStr='"sysinfo": { "os": "Ubuntu 20.10", "authentication":"Lucat", "firewall":"ufw", "flags": [ "selinux:Not present", "kernel:5.4.0-62-generic", "cpu-bugs:cpu_meltdown", "cpu-bugs:spectre_v1", "cpu-bugs:spectre_v2", "cpu-bugs:spec_store_bypass", "cpu-bugs:l1tf", "cpu-bugs:mds", "cpu-bugs:swapgs", "cpu-bugs:itlb_multihit", "vm:VMware Virtual Platform", "arch:x86_64" ], "cpu": { "name": "Intel® Xeon® CPU E5-2680 v4 @ 2.40GHz", "threads": 2 }, "memory": { "total-kb": 2006416, "type": "No ECC" }, "partitions": [ { "partition": "/dev/mapper/vg0-ubuntu", "mount-point":"/", "type":"ext4", "total-kb":13343816, "lvm":"LVM" },{ "partition": "/dev/sda2", "mount-point":"/boot", "type":"ext4", "total-kb":999320, "lvm":"--" },{ "partition": "/dev/mapper/vg2-log", "mount-point":"/var/log", "type":"ext4", "total-kb":10251576, "lvm":"LVM" },{ "partition": "/dev/mapper/vg1-home", "mount-point":"/home", "type":"ext4", "total-kb":515795384, "lvm":"LVM" } ] }' # ListenStr=', "listen-ports": [ { "binding": "*", "port": 3283, "process-owner": "ARDAgent", "process-user": "csadmin", "protocol": "TCP", "firewall-rule": null }, { "binding": "127.0.0.1", "port": 23053, "process-owner": "Growl", "process-user": "csadmin", "protocol": "TCP", "firewall-rule": null }, { "binding": "[::1]", "port": 23053, "process-owner": "Growl", "process-user": "csadmin", "protocol": "TCP", "firewall-rule": null }, { "binding": "*", "port": 1581, "process-owner": "dsmcad", "process-user": "root", "protocol": "TCP", "firewall-rule": null } ]'
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# security patches # security patches
...@@ -188,13 +201,12 @@ if [ -n "$SecurityPatches" ]; then ...@@ -188,13 +201,12 @@ if [ -n "$SecurityPatches" ]; then
do do
OUTPUT+="{ \"installed-version\": \"\", \"new-version\": \"\", \"package\": \"$Patch\", \"sources\": [ \"Apple\",\"Apple\" ] }," OUTPUT+="{ \"installed-version\": \"\", \"new-version\": \"\", \"package\": \"$Patch\", \"sources\": [ \"Apple\",\"Apple\" ] },"
done <<< "$SecurityPatches" done <<< "$SecurityPatches"
# Eliminate the final comma
SecurityPatchStr=", \"security-patches\": [ "${OUTPUT%%,}" ]" SecurityPatchStr=", \"security-patches\": [ "${OUTPUT%%,}" ]"
else else
SecurityPatchStr="" SecurityPatchStr=""
fi fi
# Ex: # Ex:
# SecurityPatchStr=', "security-patches": [ { "installed-version": "", "new-version": "", "package": "macOS Catalina Security Update 2021-003-10.15.7", "sources": } ]' # SecurityPatchStr=', "security-patches": [ { "installed-version": "", "new-version": "", "package": "macOS Catalina Security Update 2021-003-10.15.7", "sources": [ "Apple","Apple" ] } ]'
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
...@@ -205,7 +217,7 @@ NetworkStr="\"network\": { \"hostname\": \"$(hostname -f)\"$AliasName }" ...@@ -205,7 +217,7 @@ NetworkStr="\"network\": { \"hostname\": \"$(hostname -f)\"$AliasName }"
OBSERVATIONS="{ ${SysinfoStr//\"--\"/null}, ${NetworkStr}${ListenStr//\"--\"/null}${SecurityPatchStr} }" OBSERVATIONS="{ ${SysinfoStr//\"--\"/null}, ${NetworkStr}${ListenStr//\"--\"/null}${SecurityPatchStr} }"
# 4. Upload results # 4. Upload results
curl --silent -X POST "$MONITOR_RESTAPI_URL/hosts/monitor?token=$SOURCE_TOKEN" \ /usr/bin/curl --silent -X POST "$MONITOR_RESTAPI_URL/hosts/monitor?token=$SOURCE_TOKEN" \
-H "accept: application/json" \ -H "accept: application/json" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "$OBSERVATIONS" -d "$OBSERVATIONS"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment