diff --git a/VERSION b/VERSION index 5d998c4..7c05039 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ -9.2.0.8 -9.2.0.8 +9.2.0.9 +9.2.0.9 diff --git a/app.manifest b/app.manifest index 88ce30d..ad13046 100644 --- a/app.manifest +++ b/app.manifest @@ -29,7 +29,7 @@ "id": { "group": null, "name": "TA-nix", - "version": "9.2.0.8" + "version": "9.2.0.9" }, "license": { "name": "Splunk Software License Agreement", diff --git a/bin/bandwidth.sh b/bin/bandwidth.sh index 10bb027..7499478 100755 --- a/bin/bandwidth.sh +++ b/bin/bandwidth.sh @@ -79,6 +79,10 @@ elif [ "$KERNEL" = "HP-UX" ] ; then FILTER='($0 ~ "Name|sar| lo") {next}' # shellcheck disable=SC2016 FORMAT='{Name=$1; rxPackets_PS=$5; txPackets_PS=$7; rxKB_PS=?; txKB_PS=?}' +elif [ "$KERNEL" = "OpenBSD" ] ; then + CMD='eval ifconfig -a | awk "/UP/ && /RUNNING/ && \$1 != \"lo0:\" {print substr(\$1, 1, length(\$1) - 1)}" | while read -r int; do echo $int $(netstat -bnI $int -w 1 | head -n4 | tail -n1) $(netstat -nI $int -w 1 | head -n 4 | tail -n1 ); done' + # shellcheck disable=SC2016 + FORMAT='{Name=$1; rxPackets_PS=$6; txPackets_PS=$8; rxKB_PS=$2/1024; txKB_PS=$2/1024}' elif [ "$KERNEL" = "FreeBSD" ] ; then CMD='sar -n DEV 1 2' # shellcheck disable=SC2016 diff --git a/bin/common.sh b/bin/common.sh index adbbe52..a1b7a2b 100755 --- a/bin/common.sh +++ b/bin/common.sh @@ -71,6 +71,9 @@ case "x$KERNEL" in ;; "xFreeBSD") ;; + "xOpenBSD") + AWK=gawk + ;; "xAIX") ;; "xHP-UX") diff --git a/bin/cpu.sh b/bin/cpu.sh index 4657a72..935eef0 100755 --- a/bin/cpu.sh +++ b/bin/cpu.sh @@ -145,6 +145,20 @@ elif [ "$KERNEL" = "Darwin" ] ; then pctSystem = remove_char($5, "%"); pctIdle = remove_char($7, "%"); }' +elif [ "$KERNEL" = "OpenBSD" ] ; then + CMD='eval top -1 -b; top -b' + assertHaveCommand "$CMD" + # shellcheck disable=SC2016 + FILTER='($0 !~ "^([0-9]+[\t ]+)?CPU"){next;}' + # shellcheck disable=SC2016 + FORMAT='{ + if ($1 ~ /^[0-9]+$/) + name="all"; + else if ($1 ~ /^CPU[0-9]+$/) + name=substr($1,4); + else name=0; + printf "%s\t%s\t%s\t%s\t%s\t%s",name,substr($3,1,length($3)-1),substr($5,1,length($5)-1),substr($7,1,length($7)-1),substr($11,1,length($11)-1),substr($13,1,length($13)-1) + }' elif [ "$KERNEL" = "FreeBSD" ] ; then CMD='eval top -P -d2 c; top -d2 c' assertHaveCommand "$CMD" diff --git a/bin/cpu_metric.sh b/bin/cpu_metric.sh index b1f30f6..9e293f1 100755 --- a/bin/cpu_metric.sh +++ b/bin/cpu_metric.sh @@ -167,6 +167,26 @@ elif [ "$KERNEL" = "Darwin" ] ; then OS_version=OS_version; IP_address=IP_address; }' +elif [ "$KERNEL" = "OpenBSD" ] ; then + CMD='eval top -1 -b; top -b' + assertHaveCommand "$CMD" + # shellcheck disable=SC2016 + FILTER='($0 !~ "^([0-9]+[\t ]+)?CPU"){next;}' + # shellcheck disable=SC2016 + DEFINE="-v OSName=$(uname -s) -v OS_version=$(uname -r) -v IP_address=$(ifconfig -a | grep 'inet ' | grep -v 127.0.0.1 | cut -d\ -f2 | head -n 1)" + # shellcheck disable=SC2016 + FORMAT='{ + if ($1 ~ /^[0-9]+$/) + cpu="all"; + else if ($1 ~ /^CPU[0-9]+$/) + cpu=substr($1,4); + else cpu=0; + pctUser=substr($3,1,length($3)-1); + pctNice=substr($5,1,length($5)-1); + pctSystem=substr($7,1,length($7)-1); + pctIowait=substr($11,1,length($11)-1); + pctIdle=substr($13,1,length($13)-1); + }' elif [ "$KERNEL" = "FreeBSD" ] ; then CMD='eval top -P -d2 c; top -d2 c' assertHaveCommand "$CMD" diff --git a/bin/df.sh b/bin/df.sh index 6664ff4..0b1cea0 100755 --- a/bin/df.sh +++ b/bin/df.sh @@ -232,6 +232,30 @@ elif [ "$KERNEL" = "Darwin" ] ; then printf "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", $1, fsTypes[$NF], $2, $3, $4, $5, $6+$7, $6, $7, $8, $9; }' +elif [ "$KERNEL" = "OpenBSD" ] ; then + assertHaveCommand mount + assertHaveCommand df + CMD='eval mount -t nodevfs,nonfs,noswap,nocd9660; df -ih -t nodevfs,nonfs,noswap,nocd9660' + # shellcheck disable=SC2016 + BEGIN='BEGIN { OFS = "\t" }' + #Maps fsType + # shellcheck disable=SC2016 + MAP_FS_TO_TYPE='/ on / { + for (i = 1; i <= NF; i++){ + if ($i == "on" && $(i + 1) ~ /^\/.*/) + key = $(i + 1); + } + fsTypes[key] = $5; + }' + # Append Type and Inode headers to the main header and print respective fields from values stored in MAP_FS_TO_TYPE variables + # shellcheck disable=SC2016 + PRINTF='/^Filesystem/ { + print "Filesystem\tType\tSize\tUsed\tAvail\tUse%%\tInodes\tIUsed\tIFree\tIUse%%\tMountedOn\n"; + } + $0 !~ /^Filesystem/ && $0 !~ / on / { + printf "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", $1, fsTypes[$NF], $2, $3, $4, $5, $6+$7, $6, $7, $8, $9; + }' + elif [ "$KERNEL" = "FreeBSD" ] ; then assertHaveCommand mount assertHaveCommand df diff --git a/bin/df_metric.sh b/bin/df_metric.sh index 5d5c4f1..cb79d07 100755 --- a/bin/df_metric.sh +++ b/bin/df_metric.sh @@ -252,6 +252,32 @@ elif [ "$KERNEL" = "Darwin" ] ; then printf "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", $1, fsTypes[$NF], $2, $3, $4, substr($5, 1, length($5) - 1), $6+$7, $6, $7, substr($8, 1, length($8) - 1), $9, OSName, OS_version, IP_address, IPv6_Address; }' +elif [ "$KERNEL" = "OpenBSD" ] ; then + assertHaveCommand mount + assertHaveCommand df + CMD='eval mount -t nodevfs,nonfs,noswap,nocd9660; df -ih -t nodevfs,nonfs,noswap,nocd9660' + # Filters have been applied to get rid of IPv6 addresses designated for special usage to extract only the global IPv6 address. + # shellcheck disable=SC2016 + DEFINE="-v OSName=$(uname -s) -v OS_version=$(uname -r) -v IP_address=$(ifconfig -a | grep 'inet ' | grep -v 127.0.0.1 | cut -d\ -f2 | head -n 1) -v IPv6_Address=$(ifconfig -a | grep inet6 | grep -v ' ::1 ' | grep -v ' ::1/' | grep -v ' ::1%' | grep -v ' fe80::' | grep -v ' 2002::' | grep -v ' ff00::' | head -n 1 | xargs | cut -d '/' -f 1 | cut -d '%' -f 1 | cut -d ' ' -f 2)" + BEGIN='BEGIN { OFS = "\t" }' + #Maps fsType + # shellcheck disable=SC2016 + MAP_FS_TO_TYPE='/ on / { + for (i = 1; i <= NF; i++){ + if ($i == "on" && $(i + 1) ~ /^\/.*/) + key = $(i + 1); + } + fsTypes[key] = $5; + }' + # Append Type and Inode headers to the main header and print respective fields from values stored in MAP_FS_TO_TYPE variables + # shellcheck disable=SC2016 + PRINTF='/^Filesystem/ { + printf "Filesystem\tType\t1K-blocks\tUsed\tAvail\tUse%%\tInodes\tIUsed\tIFree\tIUse%%\tMountedOn\tOSName\tOS_version\tIP_address\tIPv6_Address\n"; + } + $0 !~ /^Filesystem/ && $0 !~ / on / { + printf "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", $1, fsTypes[$NF], $2, $3, $4, substr($5, 1, length($5) - 1), $6+$7, $6, $7, substr($8, 1, length($8) - 1), $9, OSName, OS_version, IP_address, IPv6_Address; + }' + elif [ "$KERNEL" = "FreeBSD" ] ; then assertHaveCommand mount assertHaveCommand df diff --git a/bin/hardware.sh b/bin/hardware.sh index 81c68e9..10c7e06 100755 --- a/bin/hardware.sh +++ b/bin/hardware.sh @@ -188,6 +188,29 @@ elif [ "$KERNEL" = "HP-UX" ] ; then OUTPUT=$(swapinfo -tm) MEMORY_REAL=$(echo "$OUTPUT" | awk '$1=="memory" {print $2 " MB"; exit}') MEMORY_SWAP=$(echo "$OUTPUT" | awk '$1=="dev" {print $2 " MB"; exit}') +elif [ "$KERNEL" = "OpenBSD" ] ; then + assertHaveCommand sysctl + assertHaveCommand df + assertHaveCommand ifconfig + assertHaveCommand dmesg + assertHaveCommand top + # CPUs + CPU_TYPE=$(sysctl -n hw.model) + CPU_CACHE= + CPU_COUNT=$(sysctl -n hw.ncpu) + # HDs + HARD_DRIVES=$(df -h | awk '/^\/dev/ {sub("^.*\134/", "", $1); drives[$1] = $2} END {for(d in drives) printf("%s: %s; ", d, drives[d])}') + # NICs + IFACE_NAME=$(ifconfig -a | awk '/^[a-z0-9]+: / {sub(":", "", $1); iface=$1} /media: / {print iface}') + for NIC in $IFACE_NAME; do + NIC=$(echo $NIC | sed -E 's/[0-9]+$//') + NIC_TYPE="$NIC_TYPE,$(whatis $NIC | sed -E 's/^.* - //')" + done + NIC_TYPE=${NIC_TYPE#,} + NIC_COUNT=$(echo $IFACE_NAME | wc -w) + # memory + MEMORY_REAL=$(sysctl -n hw.physmem) + MEMORY_SWAP=$(systat -b swap | gawk '/^DISK/{p=1;next}p==1{swap+=$2}END{print int(swap/2)}') elif [ "$KERNEL" = "FreeBSD" ] ; then assertHaveCommand sysctl assertHaveCommand df @@ -195,9 +218,9 @@ elif [ "$KERNEL" = "FreeBSD" ] ; then assertHaveCommand dmesg assertHaveCommand top # CPUs - CPU_TYPE=$(sysctl hw.model | sed 's/^.*: //') + CPU_TYPE=$(sysctl -n hw.model) CPU_CACHE= - CPU_COUNT=$(sysctl hw.ncpu | sed 's/^.*: //') + CPU_COUNT=$(sysctl -n hw.ncpu) # HDs HARD_DRIVES=$(df -h | awk '/^\/dev/ {sub("^.*\134/", "", $1); drives[$1] = $2} END {for(d in drives) printf("%s: %s; ", d, drives[d])}') # NICs @@ -205,7 +228,7 @@ elif [ "$KERNEL" = "FreeBSD" ] ; then NIC_TYPE=$(dmesg | awk '(index($0, iface) && index($0, " port ")) {sub("^.*<", ""); sub(">.*$", ""); print $0}' iface="$IFACE_NAME" | head -1) NIC_COUNT=$(ifconfig -a | grep -c media) # memory - MEMORY_REAL=$(sysctl hw.physmem | awk '{print $2/(1024*1024) "MB"}') + MEMORY_REAL=$(sysctl -n hw.physmem) MEMORY_SWAP=$(top -Sb 0 | awk '/^Swap: / {print $2 "B"}') fi diff --git a/bin/interfaces.sh b/bin/interfaces.sh index 50a7a0c..dc37dd1 100755 --- a/bin/interfaces.sh +++ b/bin/interfaces.sh @@ -469,6 +469,27 @@ elif [ "$KERNEL" = "HP-UX" ] ; then echo "$HEADER" echo "$out" fi +elif [ "$KERNEL" = "OpenBSD" ] ; then + assertHaveCommand ifconfig + assertHaveCommand netstat + + CMD_LIST_INTERFACES='ifconfig -a' + # shellcheck disable=SC2016 + CHOOSE_ACTIVE='/^[a-z0-9]+: / {sub(":", "", $1); iface=$1} /media: / {print iface}' + UNIQUE='sort -u' + # shellcheck disable=SC2016 + GET_MAC='{$1 == "lladdr" && mac = $2}' + # shellcheck disable=SC2016 + GET_IP='/ (netmask|prefixlen) / {for (i=1; i<=NF; i++) {if ($i == "inet") IPv4 = $(i+1); if ($i == "inet6") IPv6 = $(i+1)}}' + out=$($CMD_LIST_INTERFACES | tee "$TEE_DEST" | awk "$CHOOSE_ACTIVE" | $UNIQUE | tee -a "$TEE_DEST") + lines=$(echo "$out" | wc -l) + if [ "$lines" -gt 0 ]; then + echo "$HEADER" + fi + for iface in $out + do + echo "$iface $(ifconfig $iface | awk "$GET_MAC $GET_IP END {printf \"%s %s %s\", mac, IPv4, IPv6}") $(echo $(netstat -bnI $iface -w1 | head -n4 | tail -n1) $(netstat -neI $iface -w1 | head -n4 | tail -n1) | awk "{printf \"%s %s %s %s %s\", \$9, \$1, \$6, \$2, \$8}") auto auto" + done elif [ "$KERNEL" = "FreeBSD" ] ; then assertHaveCommand ifconfig assertHaveCommand netstat diff --git a/bin/interfaces_metric.sh b/bin/interfaces_metric.sh index 2ab3ff6..017d1c8 100755 --- a/bin/interfaces_metric.sh +++ b/bin/interfaces_metric.sh @@ -485,6 +485,30 @@ elif [ "$KERNEL" = "HP-UX" ] ; then echo "$HEADER" echo "$out" fi +elif [ "$KERNEL" = "OpenBSD" ] ; then + assertHaveCommand ifconfig + assertHaveCommand netstat + + CMD_LIST_INTERFACES='ifconfig -a' + # shellcheck disable=SC2016 + CHOOSE_ACTIVE='/^[a-z0-9]+: / {sub(":", "", $1); iface=$1} /media: / {print iface}' + UNIQUE='sort -u' + # shellcheck disable=SC2016 + GET_MAC='{$1 == "lladdr" && mac = $2}' + # shellcheck disable=SC2016 + GET_IP='/ (netmask|prefixlen) / {for (i=1; i<=NF; i++) {if ($i == "inet") IPv4 = $(i+1); if ($i == "inet6") IPv6 = $(i+1)}}' + out=$($CMD_LIST_INTERFACES | tee "$TEE_DEST" | awk "$CHOOSE_ACTIVE" | $UNIQUE | tee -a "$TEE_DEST") + lines=$(echo "$out" | wc -l) + INT=$(netstat -nr | awk '$1 == "default" {print $NF; exit}') + IP4=$(ifconfig $INT | awk '$1=="inet"{print $2;p=1;exit}END{if (p!=1) print ""}') + IP6=$(ifconfig $INT | awk '$1=="inet6" && $2!~/%vio0$/{print $2;p=1;exit}END{if (p!=1) print ""}') + if [ "$lines" -gt 0 ]; then + echo "$HEADER" + fi + for iface in $out + do + echo "$iface $(ifconfig $iface | awk "$GET_MAC $GET_IP END {printf \"%s %s %s\", mac, IPv4, IPv6}") $(echo $(netstat -bnI $iface -w1 | head -n4 | tail -n1) $(netstat -neI $iface -w1 | head -n4 | tail -n1) | awk "{printf \"%s %s %s %s %s\", \$9, \$1, \$6, \$2, \$8}") auto auto $(uname -s) $(uname -r) $IP4 $IP6" + done elif [ "$KERNEL" = "FreeBSD" ] ; then assertHaveCommand ifconfig assertHaveCommand netstat diff --git a/bin/iostat.sh b/bin/iostat.sh index 334992d..a0c57e8 100755 --- a/bin/iostat.sh +++ b/bin/iostat.sh @@ -22,6 +22,12 @@ elif [ "$KERNEL" = "AIX" ] ; then assertHaveCommand "$CMD" # considers the disks, kb_read and kb_wrtn columns and returns output of the second interval FILTER='/^cd/ {next} /Disks/ && /Kb_read/ && /Kb_wrtn/ {f++;} f==2' +elif [ "$KERNEL" = "OpenBSD" ] ; then + CMD='systat -B iostat' + assertHaveCommand "$CMD" + HEADER="Device rB/s wB/s r/s w/s" + HEADERIZE="BEGIN {print \"$HEADER\"}" + FILTER=$HEADERIZE'/^[^ \t]/ && !/^(DEVICE|Totals)/{printf "%-7s %.2f %.2f %d %d\n", $1, $2/1024, $3/1024, $4, $5}' elif [ "$KERNEL" = "FreeBSD" ] ; then CMD='iostat -x -c 2' assertHaveCommand "$CMD" diff --git a/bin/iostat_metric.sh b/bin/iostat_metric.sh index 80d101b..c171424 100755 --- a/bin/iostat_metric.sh +++ b/bin/iostat_metric.sh @@ -35,6 +35,13 @@ elif [ "$KERNEL" = "AIX" ] ; then FILTER='/^cd/ {next} /Disks/ && /Kb_read/ && /Kb_wrtn/ {f++;} f==2' # shellcheck disable=SC2016 PRINTF='{if ($0~/Disks/ && /Kb_read/ && /Kb_wrtn/) {printf "%s OSName OS_version IP_address \n", $0} else if (NF!=0) {printf "%s %s %s %s\n", $0, OSName, OS_version/1000, IP_address}}' +elif [ "$KERNEL" = "OpenBSD" ] ; then + CMD='systat -B iostat' + assertHaveCommand "$CMD" + DEFINE="-v OSName=$(uname -s) -v OS_version=$(uname -r) -v IP_address=$(ifconfig $(netstat -nr | awk '$1 == "default" {print $NF; exit}') | awk '$1=="inet"{print $2;p=1;exit}END{if (p!=1) print ""}')" + HEADER="Device rB/s wB/s r/s w/s OSName OS_version IP_address" + HEADERIZE="BEGIN {print \"$HEADER\"}" + FILTER=$HEADERIZE'/^[^ \t]/ && !/^(DEVICE|Totals)/{printf "%-7s %.2f %.2f %d %d %s %s %s\n", $1, $2/1024, $3/1024, $4, $5, OSName, OS_version, IP_address}' elif [ "$KERNEL" = "FreeBSD" ] ; then CMD='iostat -x -c 2' assertHaveCommand "$CMD" diff --git a/bin/lastlog.sh b/bin/lastlog.sh index fbab360..d2fa223 100755 --- a/bin/lastlog.sh +++ b/bin/lastlog.sh @@ -29,6 +29,12 @@ elif [ "$KERNEL" = "Darwin" ] ; then FILTER='{if ($0 == "") exit; if ($1 ~ /reboot|shutdown/ || $1 in users) next; users[$1]=1}' # shellcheck disable=SC2016 FORMAT='{username = $1; from = ($0 !~ / /) ? $3 : ""; latest = $(NF-6) " " $(NF-5) " " $(NF-4) " " $(NF-3)}' +elif [ "$KERNEL" = "OpenBSD" ] ; then + CMD='last' + # shellcheck disable=SC2016 + FILTER='{if ($0 == "") exit; if ($1 ~ /reboot|shutdown/ || $1 in users) next; users[$1]=1}' + # shellcheck disable=SC2016 + FORMAT='{username = $1; from = (NF==10) ? $3 : ""; latest = $(NF-6) " " $(NF-5) " " $(NF-4) " " $(NF-3)}' elif [ "$KERNEL" = "HP-UX" ] ; then CMD='lastb -Rx' # shellcheck disable=SC2016 diff --git a/bin/lsof.sh b/bin/lsof.sh index e641e04..429e5a2 100755 --- a/bin/lsof.sh +++ b/bin/lsof.sh @@ -5,6 +5,11 @@ # shellcheck disable=SC1091 . "$(dirname "$0")"/common.sh +if [ "$KERNEL" = "OpenBSD" ] ; then + fstat | awk '/^USER/{print "COMMAND PID USER FD MOUNT"} $5 ~ /^\// {print $2, $3, $1, $4, $5} $5 !~ /^\// && !/^USER/ {print $2, $3, $1, $4, $5, $6, $7, $8, $9, $10, $11}' + exit 0 +fi + assertHaveCommand lsof CMD='lsof -nPs +c 0' diff --git a/bin/netstat.sh b/bin/netstat.sh index 0434795..850e47f 100755 --- a/bin/netstat.sh +++ b/bin/netstat.sh @@ -39,7 +39,7 @@ elif [ "$KERNEL" = "Darwin" ] ; then FORMAT='{gsub("[46]", "", $1)}' elif [ "$KERNEL" = "HP-UX" ] ; then CMD='eval netstat -an | egrep "tcp|udp"' -elif [ "$KERNEL" = "FreeBSD" ] ; then +elif [ "$KERNEL" = "FreeBSD" ] || [ "$KERNEL" = "OpenBSD" ] ; then # shellcheck disable=SC2089 CMD='eval netstat -an | egrep "tcp|udp"' # shellcheck disable=SC2016 diff --git a/bin/openPorts.sh b/bin/openPorts.sh index 1b8a53f..8f46491 100755 --- a/bin/openPorts.sh +++ b/bin/openPorts.sh @@ -52,7 +52,7 @@ elif [ "$KERNEL" = "HP-UX" ] ; then FORMAT='{gsub("[46]", "", $1); proto=$1; sub("^.*[^0-9]", "", $4); port=$4}' # shellcheck disable=SC2016 FILTER='{if ($4 == "") next}' -elif [ "$KERNEL" = "FreeBSD" ] ; then +elif [ "$KERNEL" = "FreeBSD" ] || [ "$KERNEL" = "OpenBSD" ] ; then # shellcheck disable=SC2089 CMD='eval netstat -ln | egrep "^tcp|^udp"' HEADERIZE="BEGIN {print \"$HEADER\"}" diff --git a/bin/package.sh b/bin/package.sh index f9573fd..ddccd69 100755 --- a/bin/package.sh +++ b/bin/package.sh @@ -46,6 +46,12 @@ elif [ "$KERNEL" = "HP-UX" ] ; then FILTER='/^#/ {next} $1=="" {next}' # shellcheck disable=SC2016 FORMAT='{release="?"; group="?"; vendor="?"; name=$1; version=$2; arch=$3} NF==4 {vendor=$4}' +elif [ "$KERNEL" = "OpenBSD" ] ; then + CMD=pkg_info + HEADER='NAME VERSION ARCH ' + HEADERIZE="BEGIN {print \"$HEADER\"; arch=\"$(arch -s)\"}" + #PRINTF='{ printf "%-50s %-50s %s\n",$1,$2,$3}' + PRINTF='{name=gensub(/-[0-9].*$/,"",1,$1); suffix=gensub(/^.*-([0-9][^-]*)/,"",1,$1); if (suffix!="") suffix="," suffix; version=gensub(/^.*-([0-9][^-]*)-?.*$/,"\\1",1,$1); printf "%-50s %-50s %s\n", name suffix, version, arch}' elif [ "$KERNEL" = "FreeBSD" ] ; then # the below syntax is valid when using zsh, bash, ksh if [[ $KERNEL_RELEASE =~ 10.* ]] || [[ $KERNEL_RELEASE =~ 11.* ]] || [[ $KERNEL_RELEASE =~ 12.* ]] || [[ $KERNEL_RELEASE =~ 13.* ]]; then diff --git a/bin/protocol.sh b/bin/protocol.sh index 0ab8ba2..d632313 100755 --- a/bin/protocol.sh +++ b/bin/protocol.sh @@ -65,7 +65,7 @@ elif [ "$KERNEL" = "HP-UX" ] ; then SECTION_TCP='inTCP && /retransmited$/ {TCPrexmits=$1} inTCP && /out of order/ {TCPreorder=$1} inTCP && /[0-9] packets received$/ {TCPpktRecv=$1} inTCP && /[0-9] packets sent$/ {TCPpktSent=$1}' # shellcheck disable=SC2016 SECTION_UDP='inUDP && /packets received/ {UDPpktRecv=$1} inUDP && /packets sent/ {UDPpktSent=$1} inUDP && /packet receive errors/ {UDPpktLost=$1} inUDP && /packets to unknown port received/ {UDPunkPort=$1}' - elif [ "$KERNEL" = "FreeBSD" ] ; then + elif [ "$KERNEL" = "FreeBSD" ] || [ "$KERNEL" = "OpenBSD" ] ; then # shellcheck disable=SC2016 FIGURE_SECTION='/^ip:$/ {inIP=1;inTCP=0;inUDP=0} /^tcp:$/ {inIP=0;inTCP=1;inUDP=0} /^udp:$/ {inIP=0;inTCP=0;inUDP=1} {if (NF==1 && $1 !~ /^ip:$|^udp:$|^tcp:$/) inIP=inTCP=inUDP=0}' # shellcheck disable=SC2016 diff --git a/bin/ps.sh b/bin/ps.sh index 56816d6..41468aa 100755 --- a/bin/ps.sh +++ b/bin/ps.sh @@ -6,7 +6,7 @@ . "$(dirname "$0")"/common.sh # shellcheck disable=SC2166 -if [ "$KERNEL" = "Linux" -o "$KERNEL" = "Darwin" -o "$KERNEL" = "FreeBSD" ] ; then +if [ "$KERNEL" = "Linux" -o "$KERNEL" = "Darwin" -o "$KERNEL" = "FreeBSD" -o "$KERNEL" = "OpenBSD" ] ; then assertHaveCommand ps CMD='ps auxww' elif [ "$KERNEL" = "AIX" ] ; then diff --git a/bin/ps_metric.sh b/bin/ps_metric.sh index 81d601a..b92e64d 100755 --- a/bin/ps_metric.sh +++ b/bin/ps_metric.sh @@ -8,7 +8,7 @@ . "$(dirname "$0")"/common.sh # shellcheck disable=SC2166 -if [ "$KERNEL" = "Linux" -o "$KERNEL" = "Darwin" -o "$KERNEL" = "FreeBSD" ] ; then +if [ "$KERNEL" = "Linux" -o "$KERNEL" = "Darwin" -o "$KERNEL" = "FreeBSD" -o "$KERNEL" = "OpenBSD" ] ; then assertHaveCommand ps CMD='ps auxww' if [ "$KERNEL" = "Linux" ] ; then @@ -17,7 +17,7 @@ if [ "$KERNEL" = "Linux" -o "$KERNEL" = "Darwin" -o "$KERNEL" = "FreeBSD" ] ; th else DEFINE="-v OSName=$(cat /etc/*release | grep '\bNAME=' | cut -d '=' -f2 | tr ' ' '_' | cut -d\" -f2) -v OS_version=$(cat /etc/*release | grep -E '\b(VERSION|BUILD)_ID=' | cut -d '=' -f2 | cut -d\" -f2) -v IP_address=$(ip -4 route show default | awk '{print $9}') -v IPv6_Address=$(ip -6 -brief address show scope global | xargs | cut -d ' ' -f 3 | cut -d '/' -f 1)" fi - elif [ "$KERNEL" = "Darwin" -o "$KERNEL" = "FreeBSD" ] ; then + elif [ "$KERNEL" = "Darwin" -o "$KERNEL" = "FreeBSD" -o "$KERNEL" = "OpenBSD" ] ; then # Filters have been applied to get rid of IPv6 addresses designated for special usage to extract only the global IPv6 address. DEFINE="-v OSName=$(uname -s) -v OS_version=$(uname -r) -v IP_address=$(ifconfig -a | grep 'inet ' | grep -v 127.0.0.1 | cut -d\ -f2 | head -n 1) -v IPv6_Address=$(ifconfig -a | grep inet6 | grep -v ' ::1 ' | grep -v ' ::1/' | grep -v ' ::1%' | grep -v ' fe80::' | grep -v ' 2002::' | grep -v ' ff00::' | head -n 1 | xargs | cut -d '/' -f 1 | cut -d '%' -f 1 | cut -d ' ' -f 2)" fi diff --git a/bin/rlog.sh b/bin/rlog.sh index a791ca6..ace5150 100755 --- a/bin/rlog.sh +++ b/bin/rlog.sh @@ -63,6 +63,8 @@ elif [ "$KERNEL" = "Darwin" ] ; then : elif [ "$KERNEL" = "HP-UX" ] ; then : +elif [ "$KERNEL" = "OpenBSD" ] ; then + : elif [ "$KERNEL" = "FreeBSD" ] ; then : fi diff --git a/bin/service.sh b/bin/service.sh index d5c620c..377893f 100755 --- a/bin/service.sh +++ b/bin/service.sh @@ -187,6 +187,22 @@ elif [ "$KERNEL" = "Darwin" ] ; then POSTPROCESS='END { if (SPLUNKD==0) { printf "%s app=\"Splunk\" StartMode=Disabled\n", DATE } }' +elif [ "$KERNEL" = "OpenBSD" ] ; then + enabled=" $(/usr/sbin/rcctl ls on) " + failed=" $(doas /usr/sbin/rcctl ls failed) " + rogue=" $(doas /usr/sbin/rcctl ls rogue) " + running=" $(doas /usr/sbin/rcctl ls started) " + for svc in $(/usr/sbin/rcctl ls all); do + enabled=false + echo $enabled | grep " $svc " && enabled=true + failed=false + echo $enabled | grep " $svc " && failed=true + rogue=false + echo $enabled | grep " $svc " && rogue=true + state=stopped + echo $enabled | grep " $svc " && state=running + date "+%a %b %e %H:%M:%S %Z %Y type=rcctl app=$svc, enabled=$enabled, failed=$failed, rogue=$rogue, running=$running" + done else # Exits failUnsupportedScript diff --git a/bin/sshdChecker.sh b/bin/sshdChecker.sh index 0a2b545..79586ee 100755 --- a/bin/sshdChecker.sh +++ b/bin/sshdChecker.sh @@ -6,8 +6,9 @@ . "$(dirname "$0")"/common.sh SSH_CONFIG_FILE="" -if [ "$KERNEL" = "Linux" ] || [ "$KERNEL" = "SunOS" ] ; then +if [ "$KERNEL" = "Linux" ] || [ "$KERNEL" = "SunOS" ] || [ "$KERNEL" = "OpenBSD" ] ; then SSH_CONFIG_FILE=/etc/ssh/sshd_config + [ "$KERNEL" = "OpenBSD" ] && SPLUNK_HOME=/usr elif [ "$KERNEL" = "Darwin" ] ; then SSH_CONFIG_FILE=/etc/sshd_config else diff --git a/bin/time.sh b/bin/time.sh index 5fc0974..9c02c37 100755 --- a/bin/time.sh +++ b/bin/time.sh @@ -51,6 +51,8 @@ elif [ "$KERNEL" = "Darwin" ] && [ $FOUND_SNTP -eq 0 ] ; then # Mac OS 10.14.6 o echo "CONFIG=$CONFIG, SERVER=$SERVER" >> "$TEE_DEST" #With Chrony +elif [ "$KERNEL" = "OpenBSD" ]; then + CMD2="ntpctl -s all" else CMD2="chronyc -n sources" fi diff --git a/bin/update.sh b/bin/update.sh index 81d09cf..a2b0e97 100755 --- a/bin/update.sh +++ b/bin/update.sh @@ -131,6 +131,10 @@ elif [ "$KERNEL" = "Darwin" ] ; then MESSAGE="$PARSE_0 $PARSE_1 $PARSE_2 $PARSE_3" +elif [ "$KERNEL" = "OpenBSD" ] ; then + CMD="eval pkg_add -usv 2>&1 | grep -vE '(Adding quirks-|pkg_add should be run as root)' | grep ^Adding | sed -E 's/^Adding ([^:]+:)?(.*)->(.*)\(pretending\)/\2 \3/' | while read pkg ver; do name=\$(pkg_info -P \$pkg | grep -A1 ^Pkgpath:|tail -n1|cut -d/ -f2-); date \"+%a %b %e %H:%M:%S %Z %Y arch_architecture=\$(arch -s) package=\$name current_package_version=\$(echo \$pkg | sed -E \"s/\$name-//\") latest_package_version=\$ver\"; done" + #CMD="eval for f in \$(pkg_add -usv 2>&1 | grep -vE \"(Adding quirks-|pkg_add should be run as root)\" | grep ^Adding | sed -E \"s/^Adding ([^:]+:)?(.*)->(.*)\(pretending\)/\2 \3/\"); do echo \$f; done" + MESSAGE="{print}" else # Exits failUnsupportedScript diff --git a/bin/uptime.sh b/bin/uptime.sh index d6f69c5..91d75c9 100755 --- a/bin/uptime.sh +++ b/bin/uptime.sh @@ -18,7 +18,7 @@ fi # This should work for any POSIX-compliant system, but in case it doesn't # we have left the individual OS names here to be broken out later on. -if [ "$KERNEL" = "Linux" ] || [ "$KERNEL" = "SunOS" ] || [ "$KERNEL" = "AIX" ] || [ "$KERNEL" = "HP-UX" ] || [ "$KERNEL" = "Darwin" ] || [ "$KERNEL" = "FreeBSD" ] ; then +if [ "$KERNEL" = "Linux" ] || [ "$KERNEL" = "SunOS" ] || [ "$KERNEL" = "AIX" ] || [ "$KERNEL" = "HP-UX" ] || [ "$KERNEL" = "Darwin" ] || [ "$KERNEL" = "FreeBSD" ] || [ "$KERNEL" = "OpenBSD" ] ; then assertHaveCommand date assertHaveCommand ps CMD='eval date; LC_ALL=POSIX ps -o etime= -p 1' diff --git a/bin/version.sh b/bin/version.sh index 1df3c2f..cddefda 100755 --- a/bin/version.sh +++ b/bin/version.sh @@ -32,7 +32,7 @@ elif [ "$KERNEL" = "Darwin" ] ; then assertHaveCommand sw_vers os_release=$(sw_vers --productVersion) CMD="eval date ; echo MacOS ; eval uname -m ; eval uname -r ; eval uname -s ; eval uname -v ; eval uname -p; echo $os_release; echo $os_release" -elif [ "$KERNEL" = "SunOS" ] [ "$KERNEL" = "FreeBSD" ] ; then +elif [ "$KERNEL" = "SunOS" ] || [ "$KERNEL" = "FreeBSD" ] || [ "$KERNEL" = "OpenBSD" ] ; then assertHaveCommand date assertHaveCommand uname CMD='eval date ; echo $KERNEL ; eval uname -m ; eval uname -r ; eval uname -s ; eval uname -v ; eval uname -p;' diff --git a/bin/vmstat.sh b/bin/vmstat.sh index a14b9da..47d90d3 100755 --- a/bin/vmstat.sh +++ b/bin/vmstat.sh @@ -151,6 +151,26 @@ elif [ "$KERNEL" = "Darwin" ] ; then PARSE_8='/^pgswapout / {pgSwapOut=0+$2}' MASSAGE="$FUNCS $PARSE_0 $PARSE_1 $PARSE_2 $PARSE_3 $PARSE_4 $PARSE_5 $PARSE_6 $PARSE_7 $PARSE_8 $DERIVE" FILL_BLANKS='END {cSwitches=interrupts=interrupts_PS=forks="0"}' +elif [ "$KERNEL" = "OpenBSD" ] ; then + # shellcheck disable=SC2016 + CMD='eval sysctl -n hw.physmem ; vmstat -s ; top -Sb 0; `dirname $0`/hardware.sh' + FUNCS='function toMB(s) {n=0+s; if (index(s,"K")) {n /= 1024} if (index(s,"G")) {n *= 1024} return n}' + # shellcheck disable=SC2016 + PARSE_0='(NR==1) {memTotalMB=$1 / (1024*1024)}' + # shellcheck disable=SC2016 + PARSE_1='/pages being paged out$/ {pgPageOut+=$1} /forks$/ {forks+=$1} /cpu context switches$/ {cSwitches+=$1} /interrupts$/ {interrupts+=$1}' + # shellcheck disable=SC2016 + PARSE_2='/load averages:/ {loadAvg1mi=$3} /^[0-9]+ processes: / {processes=$1}' + # shellcheck disable=SC2016 + PARSE_3='/Swap: / { split($10, a, "/"); swapTotal=toMB(a[2]); swapUsed=toMB(a[1]); swapFree=swapTotal-swapFree; } /^Memory: / {memFreeMB=toMB($6)}' + # shellcheck disable=SC2016 + PARSE_4='/^CPU_COUNT/ {cpuCount=$2}' + # shellcheck disable=SC2016 + PARSE_5='($3 ~ "INTR") {nr1[NR+3]} NR in nr1 {interrupts_PS=$3}' + # shellcheck disable=SC2016 + PARSE_6='($3 ~ "pgpgin*") {nr2[NR+3]} NR in nr2 {pgPageIn_PS=$3; pgPageOut_PS=$4}' + MASSAGE="$FUNCS $PARSE_0 $PARSE_1 $PARSE_2 $PARSE_3 $PARSE_4 $PARSE_5 $PARSE_6 $DERIVE" + FILL_BLANKS='END {threads=pgSwapOut="?"}' elif [ "$KERNEL" = "FreeBSD" ] ; then # shellcheck disable=SC2016 CMD='eval sysctl hw.physmem ; vmstat -s ; top -Sb 0; `dirname $0`/hardware.sh' diff --git a/bin/vmstat_metric.sh b/bin/vmstat_metric.sh index 2a5d159..c262588 100755 --- a/bin/vmstat_metric.sh +++ b/bin/vmstat_metric.sh @@ -162,6 +162,27 @@ elif [ "$KERNEL" = "Darwin" ] ; then PARSE_8='/^pgswapout / {pgSwapOut=0+$2}' MESSAGE="$FUNCS $PARSE_0 $PARSE_1 $PARSE_2 $PARSE_3 $PARSE_4 $PARSE_5 $PARSE_6 $PARSE_7 $PARSE_8 $DERIVE" FILL_BLANKS='END {cSwitches=interrupts=interrupts_PS=forks="0"}' +elif [ "$KERNEL" = "OpenBSD" ] ; then + # shellcheck disable=SC2016 + CMD='eval sysctl -n hw.physmem ; vmstat -s ; top -Sb 0; `dirname $0`/hardware.sh' + DEFINE="-v OSName=$(uname -s) -v OS_version=$(uname -r) -v IP_address=$(ifconfig -a | grep 'inet ' | grep -v 127.0.0.1 | cut -d\ -f2 | head -n 1)" + FUNCS='function toMB(s) {n=0+s; if (index(s,"K")) {n /= 1024} if (index(s,"G")) {n *= 1024} return n}' + # shellcheck disable=SC2016 + PARSE_0='(NR==1) {memTotalMB=$1 / (1024*1024)}' + # shellcheck disable=SC2016 + PARSE_1='/pages being paged out$/ {pgPageOut+=$1} /forks$/ {forks+=$1} /cpu context switches$/ {cSwitches+=$1} /interrupts$/ {interrupts+=$1}' + # shellcheck disable=SC2016 + PARSE_2='/load averages:/ {loadAvg1mi=$3} /^[0-9]+ processes: / {processes=$1}' + # shellcheck disable=SC2016 + PARSE_3='/Swap: / { split($10, a, "/"); swapTotal=toMB(a[2]); swapUsed=toMB(a[1]); swapFree=swapTotal-swapFree; } /^Memory: / {memFreeMB=toMB($6)}' + # shellcheck disable=SC2016 + PARSE_4='/^CPU_COUNT/ {cpuCount=$2}' + # shellcheck disable=SC2016 + PARSE_5='($3 ~ "INTR") {nr1[NR+3]} NR in nr1 {interrupts_PS=$3}' + # shellcheck disable=SC2016 + PARSE_6='($3 ~ "pgpgin*") {nr2[NR+3]} NR in nr2 {pgPageIn_PS=$3; pgPageOut_PS=$4}' + MESSAGE="$FUNCS $PARSE_0 $PARSE_1 $PARSE_2 $PARSE_3 $PARSE_4 $PARSE_5 $PARSE_6 $DERIVE" + FILL_BLANKS='END {threads=pgSwapOut="?"}' elif [ "$KERNEL" = "FreeBSD" ] ; then # shellcheck disable=SC2016 CMD='eval sysctl hw.physmem ; vmstat -s ; top -Sb 0; `dirname $0`/hardware.sh' diff --git a/default/app.conf b/default/app.conf index cbf2275..efceb73 100644 --- a/default/app.conf +++ b/default/app.conf @@ -17,7 +17,7 @@ docs_section_override = AddOns:released [launcher] author = Michael Erdely -version = 9.2.0.8 +version = 9.2.0.9 description = Technical Add-on for Unix and Linux #[package] @@ -26,5 +26,5 @@ description = Technical Add-on for Unix and Linux [id] name = TA-unix -version = 9.2.0.8 +version = 9.2.0.9 diff --git a/docs/ReleaseNotes.md b/docs/ReleaseNotes.md index 9a31062..a4eae9c 100644 --- a/docs/ReleaseNotes.md +++ b/docs/ReleaseNotes.md @@ -1,5 +1,14 @@ # Technical Add-on for Unix and Linux +## Version 9.2.0.9 (2025-01-25) + +Support OpenBSD + +Changes: + +* Add OpenBSD support to the scripts +* Fix sysctl usage for FreeBSD in a couple places + ## Version 9.2.0.8 (2025-01-23) Fix df.sh and df_metric.sh diff --git a/extra/run_nix_ta_commands b/extra/run_nix_ta_commands index 64ef8ba..63340c1 100755 --- a/extra/run_nix_ta_commands +++ b/extra/run_nix_ta_commands @@ -42,9 +42,9 @@ run_hour=6 [ -r /etc/nix_ta.conf ] && . /etc/nix_ta.conf # Get the current minute now to be consistent through the script run -minute=$(date +%_M | tr -d ' ') +minute=$(printf "%d" $(date +%M)) # Get the current hour now to be consistent through the script run -hour=$(date +%_H | tr -d ' ') +hour=$(printf "%d" $(date +%H)) # Set defaults disabling force-mode and list-mode force=0 list=0