The port value in dot1dTpFdbPort MIB oid is not available in ifIndex object which is fetched in dot1dBasePortIfIndex MIB oid - snmp

I see the value 17 in the Output of dot1dTpFdbPort does not exist in the Output of dot1dBasePortIfIndex. Can anyone please explain what could be the reason for this behavior?
I would like to know under what circumstances this scenario occurs.
**Output of dot1dBasePortIfIndex:**
\[root#yyy\]# snmpwalk -v 2c -c public \<ip address\> 1.3.6.1.2.1.17.1.4.1.2
SNMPv2-SMI::mib-2.17.1.4.1.2.13 = INTEGER: 13
SNMPv2-SMI::mib-2.17.1.4.1.2.14 = INTEGER: 14
**Output of dot1dTpFdbPort:**
\[root#yyy\]# snmpwalk -v 2c -c public \<ip address\> 1.3.6.1.2.1.17.7.1.2.2.1.2
SNMPv2-SMI::mib-2.17.7.1.2.2.1.2.1.124.33.14.229.38.137 = INTEGER: 14
SNMPv2-SMI::mib-2.17.7.1.2.2.1.2.4090.0.12.41.1.205.0 = INTEGER: 13
SNMPv2-SMI::mib-2.17.7.1.2.2.1.2.4090.0.12.41.1.205.0 = INTEGER: **17**

Related

Find word in text by ID and replace other word in the same line

I have crontab with some rules. I need to find a line with server ID, and then replace the number of days at the end of the line.
$ crontab -l
00 6 * * * /home/scripts/User/19122391_User_Server_Notification_shutdown_delete.sh 64
00 16 * * * /home/scripts/User/20045967_User_Server_Notification_shutdown_delete.sh 15
ID of server: 19122391
Days: 64
So, I need to change number 64 to another, for example 100 in crontab. To find a line I use this command awk '/19122391/{print}' crontab.bak, but how to replace last number in line, I did not can find solutions.
Can I use bash script to do this?
Using awk
$ awk -i inplace '/19122391/{$NF=100}1' crontab.bak
00 6 * * * /home/scripts/User/19122391_User_Server_Notification_shutdown_delete.sh 100
00 16 * * * /home/scripts/User/20045967_User_Server_Notification_shutdown_delete.sh 15
Using sed
$ sed -i '/19122391/s/[0-9]*$/100/' crontab.bak
00 6 * * * /home/scripts/User/19122391_User_Server_Notification_shutdown_delete.sh 100
00 16 * * * /home/scripts/User/20045967_User_Server_Notification_shutdown_delete.sh 15

ELF go binaries default byte alignment

I empirically see that go ELF binaries use 16 bytes alignment. For example:
$ wget https://github.com/gardener/gardenctl/releases/download/v0.24.2/gardenctl-linux-amd64
$ readelf -W -s gardenctl-linux-amd64 | grep -E "FUNC" | wc -l
44746
$ readelf -W -s gardenctl-linux-amd64 | grep -E "0[ ]+[0-9]* FUNC" | wc -l
44744
so vast majority have 0 in their least significant byte. Is it always like that in go binaries?
This depends on the platform. If you have a source repo checked out:
% cd go/src/cmd/link/internal
% grep "funcAlign =" */*.go
amd64/l.go: funcAlign = 32
arm/l.go: funcAlign = 4 // single-instruction alignment
arm64/l.go: funcAlign = 16
mips64/l.go: funcAlign = 8
ppc64/l.go: funcAlign = 16
riscv64/l.go: funcAlign = 8
s390x/l.go: funcAlign = 16
x86/l.go: funcAlign = 16
the alignment for amd64 may go back down to 16 in the future; it is 32 for a while because of https://github.com/golang/go/issues/35881

Debugging why SPI Master is Reading Arbitary Values

I have an SPI bus between a MAX V device and an AM335x processor.
The MAX V device has an SPI setup to repeatedly send a STD_LOGIC_VECTOR defined as "x0100".
This seems to work fine. The output on a scope is repeatedly the same value.
In Linux, I seem to get either shifted data, or some random data. Using spi-tools from here https://github.com/cpb-/spi-tools
When these tools are used, I get the following:
# spi-config -d /dev/spidev0.0 -m 1 -s 10000000
# spi-pipe -d /dev/spidev0.0 -b 2 -n 1 < /dev/urandom | hexdump
0000000 0202
0000002
# spi-pipe -d /dev/spidev0.0 -b 2 -n 1 < /dev/urandom | hexdump
0000000 0a0a
0000002
# spi-pipe -d /dev/spidev0.0 -b 2 -n 1 < /dev/urandom | hexdump
0000000 2a2a
0000002
# spi-pipe -d /dev/spidev0.0 -b 2 -n 1 < /dev/urandom | hexdump
0000000 aaaa
0000002
# spi-pipe -d /dev/spidev0.0 -b 2 -n 1 < /dev/urandom | hexdump
0000000 aaaa
0000002
You can see how the device is configured there. On the scope, the MISO pin is clearly outputting "00000010 00000000" for every 16 clock cycles on SCLK. What is happening here? How can I repeatedly get the correct value from the device?
For clarity, here is the relevant parts of the device tree and the kernel configuration.
Kernel
CONFIG_SPI=y
CONFIG_SPI_MASTER=y
CONFIG_SPI_GPIO=y
CONFIG_SPI_BITBANG=y
CONFIG_SPI_OMAP24XX=y
CONFIG_SPI_TI_QSPI=y
CONFIG_SPI_SPIDEV=y
CONFIG_REGMAP_SPI=y
CONFIG_MTD_SPI_NOR=y
CONFIG_SPI_CADENCE_QUADSPI=y
Device Tree
&spi1 {
/* spi1 bus is connected to the CPLD only on CS0 */
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&spi1_pins>;
ti,pindir-d0-out-d1-in;
cpld_spidev: cpld_spidev#0 {
status = "okay";
compatible = "linux,spidev";
spi-max-frequency = <1000000>;
reg = <0>;
};
};
Also here is a screengrab of the waveforms produced.
Really the end goal is an app to report the version stated as the STD_LOGIC_VECTOR, on the MAX V device. So 0100 is intended to be version 1.00.
Use the uboot_overlay in /boot/uEnv.txt called BB-SPIDEV0-00A0.dtbo.
If you need any more info, please ask. Oh! And there is a fellow, Dr. Molloy, that had produced a book a while back.
chp08/spi/ is the location of the file you will need to test the SPI Device.
The command is simply spidev_test

print array range once string is found KSH93 Version M

My need is to print a range of array elements, minus 20 and plus 20 elements from the point "string" is found using KSH93.
I have tried many iterations of code and read many links for example,
How do I iterate over a range of numbers defined by variables in Bash?
/usr/bin/ksh93 -c 'mdm=(`/usr/sbin/mdmprpt 2>/dev/null`);
for index in "${!mdm[#]}"; do
if [[ ${mdm[$index]} =~ Fault.? ]]; then
i=${mdm[$index]};
for x in {1..$i}; do
echo $x
done
fi
done
actual result is
{1..(Faulting}
when it should print 20 lines before and or after of index 52. Ideally both.
__Raw Data__from_sample_code
mdm[32] is 6400000000000000
mdm[33] is 0000000000000000
mdm[34] is 0000000000000000
mdm[35] is 0000000000000000
mdm[36] is 00000000
mdm[37] is Symptom
mdm[38] is Information:
mdm[39] is Crash
mdm[40] is Location:
mdm[41] is [000000000010D614]
mdm[42] is IPRA.$ha_critic+114
mdm[43] is Component:
mdm[44] is COMP
mdm[45] is Exception
mdm[46] is Type:
mdm[47] is 131
mdm[48] is Data
mdm[49] is From
mdm[50] is CPU
mdm[51] is #8
mdm[52] is (Faulting
mdm[53] is CPU)
mdm[54] is backup_files
mdm[55] is cfgbackups
mdm[56] is config
mdm[57] is install.log
mdm[58] is ioscli.log
mdm[59] is pager.trace
mdm[60] is rules
mdm[61] is smit.log
mdm[62] is smit.script
mdm[63] is smit.transaction
mdm[64] is snap.pax.Z
mdm[65] is MST
mdm[66] is State:
mdm[67] is R0:
mdm[68] is 0000000000050FB4
mdm[69] is R1:
mdm[70] is F00000002FF471D0
mdm[71] is R2:
mdm[72] is 00000000038B6110
When you find the matching string you also have its (numerical) index (${index}), so just +/-20 to ${index} to get the desired range.
We'll also need some additional logic to make sure our desired range of indexes falls within the range of available indexes. Keep in mind that for an array with 'n' records the available index range will be '0 to (n-1)'.
for index in "${!mdm[#]}"
do
if [[ ${mdm[$index]} =~ Fault.? ]]
then
start=$((index-20))
end=$((index+20))
# if 'start' is less than 0 then reset it to 0
[ ${start} -lt 0 ] && start=0
for x in $( seq ${start} ${end} )
do
# break if we run out of array elements
[ "${mdm[${x}]:-undefined}" = 'undefined' ] && break
# display our numeric index and contents of associated array item
echo "${x} : ${mdm[${x}]}"
done
break
fi
done
I created a data file with 32 initial lines of 'XXXXXX', the 41 lines of sample data from the question, and an additional dozen lines of 'XXXXXX' at the end of the file; I then ran the above code snippet against the file and generated:
32 : 6400000000000000
33 : 0000000000000000
34 : 0000000000000000
35 : 0000000000000000
36 : 00000000
37 : Symptom
38 : Information:
39 : Crash
40 : Location:
41 : [000000000010D614]
42 : IPRA.$ha_critic+114
43 : Component:
44 : COMP
45 : Exception
46 : Type:
47 : 131
48 : Data
49 : From
50 : CPU
51 : #8
52 : (Faulting
53 : CPU)
54 : backup_files
55 : cfgbackups
56 : config
57 : install.log
58 : ioscli.log
59 : pager.trace
60 : rules
61 : smit.log
62 : smit.script
63 : smit.transaction
64 : snap.pax.Z
65 : MST
66 : State:
67 : R0:
68 : 0000000000050FB4
69 : R1:
70 : F00000002FF471D0
71 : R2:
72 : 00000000038B6110
Well I could just use a bunch of prints, which does do what I want, but Id think there would be a range operator I have yet to get to work.
/usr/bin/ksh93 -c 'mdm=(`/usr/sbin/mdmprpt 2>/dev/null`);
for index in "${!mdm[#]}"; do
if [[ ${mdm[$index]} =~ Fault.? ]]; then
print ${mdm[$index-20]}
print ${mdm[$index-19]}
print ${mdm[$index-18]}
print ${mdm[$index-17]}
print ${mdm[$index-16]}
print ${mdm[$index-15]}
print ${mdm[$index-14]}
print ${mdm[$index-13]}
print ${mdm[$index-12]}
print ${mdm[$index-11]}
print ${mdm[$index-10]}
print ${mdm[$index-9]}
print ${mdm[$index-8]}
print ${mdm[$index-7]}
print ${mdm[$index-6]}
print ${mdm[$index-5]}
print ${mdm[$index-4]}
print ${mdm[$index-3]}
print ${mdm[$index-2]}
print ${mdm[$index-1]}
print ${mdm[$index]}
fi
done'
6400000000000000
0000000000000000
0000000000000000
0000000000000000
00000000
Symptom
Information:
Crash
Location:
[000000000010D614]
IPRA.$ha_critic+114
Component:
COMP
Exception
Type:
131
Data
From
CPU
8
(Faulting

How to get MAC or IP Addresses of devices connected to a switch using SNMP?

Using SNMP, how do I get the MAC address of the device connected to each port on the switch? We're using HP ProCurve Switches.
I tried using the OID dot1dTpFdbPort but that seems to be giving me the MAC address of every device that's in communication with the switch, not just connected to it.
I'm trying to find the OID that will give me ports 1-48 in a list, and for each port, the MAC (or IP address) of the device connected to that port.
Thanks!
Thank you so much raz3r for your answer.
It works like a charm !
From your linux server :
$ snmpwalk -v 1 -c public xxx.xxx.xxx.xxx 1.3.6.1.2.1.17.4.3.1.2 | grep
"INTEGER: 11"
(port number 11)
Will return :
SNMPv2-SMI::mib-2.17.4.3.1.2.44.118.138.64.143.95 = INTEGER: 11
SNMPv2-SMI::mib-2.17.4.3.1.2.56.170.60.108.174.57 = INTEGER: 11
SNMPv2-SMI::mib-2.17.4.3.1.2.104.181.153.172.54.237 = INTEGER: 11
SNMPv2-SMI::mib-2.17.4.3.1.2.120.172.192.143.226.236 = INTEGER: 11
SNMPv2-SMI::mib-2.17.4.3.1.2.124.195.161.20.109.76 = INTEGER: 11
SNMPv2-SMI::mib-2.17.4.3.1.2.152.75.225.59.127.180 = INTEGER: 11
Then you can do this to find which Mac Address is connected :
$ snmpwalk -v 1 -c public xxx.xxx.xxx.xxx 1.3.6.1.2.1.17.4.3.1.1 |
grep "152.75.225.59.127.180"
Return mac address :
SNMPv2-SMI::mib-2.17.4.3.1.1.152.75.225.59.127.180 = Hex-STRING: 98
4B E1 3B 7F B4
You can make a script.sh to do this...
You were almost there :) The dot1dTpFdbPort is exactly what are you looking for, the only thing that you need is a link to the real port index.
First, take the value given by dot1dTpFdbPort.
Now query the dot1dBasePortIfIndex with the value you took before.
Let's make an example:
snmpwalk -v 2c -c xxx 192.168.x.x 1.3.6.1.2.1.17.4.3.1.1
SNMPv2-SMI::mib-2.17.4.3.1.1.0.2.253.255.213.15 = Hex-STRING: XX XX XX XX XX XX
snmpwalk -v 2c -c xxx 192.168.x.x 1.3.6.1.2.1.17.4.3.1.2
SNMPv2-SMI::mib-2.17.4.3.1.2.0.2.253.255.213.15 = INTEGER: 22
# Notice the 22 :)
snmpwalk -v 2c -c xxx 192.168.x.x 1.3.6.1.2.1.17.1.4.1.2.22
SNMPv2-SMI::mib-2.17.1.4.1.2.22 = INTEGER: 10122
Try this to have the MAC address directly in HEX :
snmpwalk -OX -v 2c -c public xxx.xxx.xxx.xxx 1.3.6.1.2.1.17.4.3.1.2
Netsnmp's snmptable may be more readable here.
Example dot1dTpFdb table retrieval:
snmptable -M +. -m +ALL -v 2c -c public -Ci 192.168.x.x BRIDGE-MIB::dot1dTpFdbTable
index dot1dTpFdbAddress dot1dTpFdbPort dot1dTpFdbStatus
'..?...' 98:4B:E1:3B:7F:B4 13 learned
// other rows snipped for brevity
Example dot1dBasePort table retrieval:
snmptable -M +. -m +ALL -v 2c -c public -Ci 192.168.x.x BRIDGE-MIB::dot1dBasePortTable
index dot1dBasePort dot1dBasePortIfIndex dot1dBasePortCircuit dot1dBasePortDelayExceededDiscards dot1dBasePortMtuExceededDiscards
13 13 10113 SNMPv2-SMI::zeroDotZero 0 0
// other rows snipped for brevity
#!/bin/bash
# This should iterate thru each active port.
HOST=xxx.xxx.xxx.xxx ## Change this to the ip address of the switch
echo
snmpwalk -v 1 -c public "$HOST" 1.3.6.1.2.1.17.4.3.1.1 | grep "$" |awk -- '{print $4":"$5":"$6":"$7":"$8":"$9}'

Resources