Passa al contenuto principale
Quando cerco di diagnosticare i problemi di rete, una delle domande che pongo sempre è: "Qual è lo stato della porta dello switch collegata all'interfaccia del modulo?" La risposta tipica è: "Devo chiedere ai tecnici di rete". Ora, grazie alla magia del Simple Network Management Protocol (SNMP) e alla macro di comando allegata, potrebbe non essere più necessario chiedere.

 

Tutti gli switch gestibili (compresi i router che fungono anche da switch) rispondono alle richieste SNMP. Il protocollo SNMP è protetto da una password, nota come stringa di comunità. In genere esiste una password per la lettura e un'altra per la scrittura. Capisco perfettamente che i responsabili della rete non vogliano fornirti la stringa di comunità di scrittura, ma se gliela chiedi gentilmente potrebbero darti quella di lettura. Dopotutto, leggere non dovrebbe causare alcun danno e, se puoi farlo da solo, non devi disturbarli. Tuttavia, prima di chiedere, potresti provare la stringa predefinita standard, che è "public". Se funziona, non c'è nemmeno bisogno di chiedere.

 

I dati SNMP sono organizzati in MIB (Management Information Base). La tabella "Interfaces" si trova nella MIB MIB-II, supportata, oserei dire, da tutti i dispositivi che supportano SNMP. La tabella include contatori di errori, byte e pacchetti. Non si tratta di molte informazioni, ma sono sufficienti per determinare lo stato di salute di base della connessione tra l'interfaccia del modulo e la rete. La MIB delle interfacce è documentata nella RFC-1213 "Management Information Base for Network Management of TCP/IP-based internets: MIB-II" (Base di informazioni di gestione per la gestione di rete di Internet basate su TCP/IP: MIB-II). È possibile trovare una copia all'indirizzo http://www.ietf.org/rfc/rfc1213.txt.

 

La macro offre tre modi per identificare la singola porta dello switch da interrogare. Il primo è tramite il nome dell'interfaccia. Utilizzando il nome, la macro usa il comando netstat per determinare l'indirizzo MAC dell'interfaccia e interroga la tabella di inoltro dello switch per determinare quale porta è associata all'indirizzo MAC.

 

get_switch_interface_stats 172.16.1.222 #sdlmux.m16.11-3
L'indirizzo IP che precede il nome è l'indirizzo IP dello switch.
È anche possibile fornire l'indirizzo MAC nel formato XX-XX-XX-XX-XX-XX. Questo è un modo per controllare la connessione dello switch dell'adattatore di standby.

 

get_switch_interface_stats 172.16.1.222 00-00-a8-44-52-22 -type mac
Infine, è possibile fornire semplicemente l'indice della porta. A seconda dello switch, questo può essere il numero effettivo della porta o un valore basato sul numero della porta. Nell'esempio seguente, il numero della porta è 48, ma l'indice è 1048.

 

get_switch_interface_stats.cm 172.16.1.222 1048 -type port
Nell'esempio di output seguente noterete che i timestamp tra il primo e il secondo passaggio sono distanziati di poco più di 60 secondi. Questo perché il timestamp viene stampato prima che vengano effettuate le query e le query richiedono tempo.

 

Perché ci sono due passaggi? Normalmente i contatori non vengono azzerati, quindi un singolo valore non dà alcuna idea della velocità con cui cambiano i contatori. La macro visualizza sia il primo che il secondo valore ed esegue la sottrazione per te.

get_switch_interface_stats.cm 172.16.1.222 1048 -type port
172.16.1.222 1048 -type port public -sleep 60

Collecting results pass 1 10-01-20.11:32:21
sleeping for 60 seconds
Collecting results pass 2 10-01-20.11:33:23


Port Index :                1048
Port name :                 "X350-48t Port 48"
Speed :                     1000
Administrative Status :     up(1) up(1)
Operation Status :          up(1) up(1)
In Octets :                 205663121 - 205568072 = 95049
In Unicast Packets :        1336981429 - 1336981157 = 272
In non-Unicast Packets :    330419202 - 330418397 = 805
In Discards :               0 - 0 = 0
In Errors :                 0 - 0 = 0
In Unknown Protocols :      0 - 0 = 0
Out Octets :                290040991 - 290003159 = 37832
Out Unicast Packets :       1570859994 - 1570859741 = 253
Out non-Unicast Packets :   4386374 - 4386362 = 12
Out Discards :              0 - 0 = 0
Out Errors :                0 - 0 = 0
Out Q Length :              0 - 0 = 0

 

In circostanze ideali non si verificano mai errori o scarti, quindi se questi contatori non sono pari a zero è necessario indagare sulla causa. Il conteggio dei pacchetti fornisce un'idea del volume. Se il volume dei pacchetti in uscita (pacchetti che vanno dallo switch all'interfaccia) è insolitamente basso, è possibile che ci sia un problema con la connessione dello switch al resto della rete. Un conteggio di pacchetti in uscita non unicast insolitamente alto può indicare che alcuni host sulla rete stanno saturando la rete con trasmissioni broadcast o multicast. Se il conteggio dei pacchetti in entrata è basso, è necessario chiedersi perché le applicazioni sul modulo non trasmettono alla velocità prevista. La chiave in questo caso è sapere cosa è insolito e ciò richiede la creazione di una linea di base.

 

Gli unici valori inequivocabili sono lo stato amministrativo e quello operativo. Se lo stato operativo risulta inattivo, significa che c'è un problema con la connessione tra lo switch e l'interfaccia. Se lo stato amministrativo risulta inattivo, significa che qualcuno ha disabilitato la connessione di rete.

 

Se il collegamento è interrotto, come è possibile interrogare la porta dello switch per sapere che il collegamento è interrotto? È possibile interrogare lo switch utilizzando l'indirizzo MAC o l'indice della porta da un altro modulo. Tuttavia, se il collegamento è interrotto da tempo, è possibile che l'indirizzo MAC sia stato eliminato dalla tabella di inoltro dello switch. In tal caso, sarà necessario utilizzare la forma dell'indice della porta del comando.

 

I comandi SNMP si trovano in >system>maint_library. Sono un porting dei comandi NET-SNMP e la documentazione è disponibile all'indirizzo http://www.net-snmp.org/. Si noti che non è necessario eseguire il server SNMP (snmpd) sul modulo per eseguire questi comandi sullo switch.

 

& get_switch_interface_stats.cm begins here
&
& get_switch_interface_stats.cm
& version 1.0 10-01-20
&
&
&begin_parameters
SWITCH switch:string,req
ID id:string,req
TYPE option(-type),name,allow(int,mac,port),=int
COMMUNITY community:string=public
SLEEP option(-sleep),number,=60
&end_parameters
&
&
&if (process_type) = 'batch' &then &do
set_ready -format off
&echo no_command_lines no_macro_lines no_input_lines
&end
&
&
& display input arguments
display_line &SWITCH& &ID& -type &TYPE& &COMMUNITY& -sleep &SLEEP&
&
&
&set_string INTERFACE_NAME ''
&set_string MAC_ADDR ''
&set_string IDX ''
&if &TYPE& = int &then &set_string INTERFACE_NAME &ID&
&if &TYPE& = mac &then &set_string MAC_ADDR &ID&
&if &TYPE& = port &then &set_string IDX &ID&
&
&
&set_string TEST (process_dir)>test
&set_string INTERFACE (process_dir)>interface
&set_string MAC (process_dir)>mac
&set_string INDEX (process_dir)>index
&set_string R1 (process_dir)>r1
&set_string R2 (process_dir)>r2
&
&
& make sure we can get a response from the switch
attach_default_output &TEST&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::sysName.0
detach_default_output
&if (file_info &TEST& blocks_used) = 0 &then &goto NOSWITCH
&
&if (length &IDX&) = 0 &then &do
&if (length &INTERFACE_NAME&) > 0 &then &do
attach_default_output &INTERFACE&
netstat -interface &INTERFACE_NAME&
detach_default_output
&if (file_info &INTERFACE& blocks_used) = 0 &then &goto NOINTERFACE
display &INTERFACE& -match 'MAC Address' -no_header -output_path &MAC&
&set_string MAC_ADDR (substr (contents &MAC& 1) 14)
&end
&if (length &MAC_ADDR&) < 17 &then &goto BADMAC
&set_string OCT1 (decimal (substr &MAC_ADDR& 1 2)x)
&set_string OCT2 (decimal (substr &MAC_ADDR& 4 2)x)
&set_string OCT3 (decimal (substr &MAC_ADDR& 7 2)x)
&set_string OCT4 (decimal (substr &MAC_ADDR& 10 2)x)
&set_string OCT5 (decimal (substr &MAC_ADDR& 13 2)x)
&set_string OCT6 (decimal (substr &MAC_ADDR& 16 2)x)
&
&
& query the forwarding table using the MAC adress to get the switch
& port number. The forwarding table is in the BRIDGE-MIB and is the
& dot1dTpFdbPort
attach_default_output &INDEX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& &+
.1.3.6.1.2.1.17.4.3.1.2.&OCT1&.&OCT2&.&OCT3&.&OCT4&.&OCT5&.&OCT6&
detach_default_output
&set_string TEMP (reverse (contents &INDEX& 1))
&set_string IDX (index (string &TEMP&) ' ')
&set_string IDX (reverse (substr (string &TEMP&) 1 (calc &IDX& - 1)))
& if after all that manipulation IDX is "OID" it means that the
& forwarding table did not contain the MAC address
&if &IDX& = OID &then &goto NOTFOUND
&
& dump the entire interface index table and use the port number from above
& to index into the table to get the port index
attach_default_output &INDEX&
snmpwalk -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifIndex
detach_default_output
&set_string IDX (substr (contents &INDEX& &IDX&) 22)
&set_string IDX (substr (string &IDX&) 1 &+
(calc (index (string &IDX&) ' ') - 1))
&end
&
&
display_line
display_line Collecting results pass 1 (date).(time)
&
&
attach_default_output &R1&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifDescr.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifSpeed.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifAdminStatus.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifOperStatus.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifLastChange.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifInOctets.&IDX&
<snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifInUcastPkts.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifInNUcastPkts.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifInDiscards.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifInErrors.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifInUnknownProtos.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifOutOctets.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifOutUcastPkts.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifOutNUcastPkts.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifOutDiscards.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifOutErrors.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifOutQLen.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifSpecific.&IDX&
<detach_default_output
&
&
& if the last 3 characters of the first line are OID it means that the
& switch does not suppor the query - probably the index is index is wrong.
&if (substr (reverse (contents &R1& 1)) 1 3) = DIO &then &goto NOIDX
&
&
display_line sleeping for &SLEEP& seconds
sleep -seconds &SLEEP&
&
&
display_line Collecting results pass 2 (date).(time)
attach_default_output &R2&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifDescr.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifSpeed.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifAdminStatus.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifOperStatus.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifLastChange.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifInOctets.&IDX&
<snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifInUcastPkts.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifInNUcastPkts.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifInDiscards.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifInErrors.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifInUnknownProtos.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifOutOctets.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifOutUcastPkts.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifOutNUcastPkts.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifOutDiscards.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifOutErrors.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifOutQLen.&IDX&
snmpget -v 2c -c &COMMUNITY& &SWITCH& RFC1213-MIB::ifSpecific.&IDX&
detach_default_output
&
&
display_line
display_line
display_line Port Index : '              ' &IDX&

&set LIDX (length &IDX&)

&set START (calc 33 + &LIDX&)
display_line Port name : '               ' (substr (contents &R1& 1) &START&)

&set START (calc 34 + &LIDX&)
display_line Speed : '                   ' &+
(calc (substr (contents &R1& 2) &START&) / 1000000)

&set START (calc 40 + &LIDX&)
display_line Administrative Status : '   ' &+
(substr (contents &R2& 3) &START&) (substr (contents &R1& 3) &START&)

&set START (calc 39 + &LIDX&)
display_line Operation Status : '        ' &+
(substr (contents &R2& 4) &START&) (substr (contents &R1& 4) &START&)

&set START (calc 39 + &LIDX&)
&set V1 (substr (contents &R1& 6) &START&)
&set V2 (substr (contents &R2& 6) &START&)
display_line In Octets : '               ' &V2& - &V1& = (calc &V2& - &V1&)

&set START (calc 42 + &LIDX&)
&set V1 (substr (contents &R1& 7) &START&)
&set V2 (substr (contents &R2& 7) &START&)
display_line In Unicast Packets : '       '&V2& - &V1& = (calc &V2& - &V1&)

&set START (calc 43 + &LIDX&)
&set V1 (substr (contents &R1& 8) &START&)
&set V2 (substr (contents &R2& 8) &START&)
display_line In non-Unicast Packets : '  ' &V2& - &V1& = (calc &V2& - &V1&)

&set START (calc 41 + &LIDX&)
&set V1 (substr (contents &R1& 9) &START&)
&set V2 (substr (contents &R2& 9) &START&)
display_line In Discards : '             ' &V2& - &V1& = (calc &V2& - &V1&)

&set START (calc 39 + &LIDX&)
&set V1 (substr (contents &R1& 10) &START&)
&set V2 (substr (contents &R2& 10) &START&)
display_line In Errors : '               ' &V2& - &V1& = (calc &V2& - &V1&)

&set START (calc 46 + &LIDX&)
< &set V1 (substr (contents &R1& 11) &START&)
&set V2 (substr (contents &R2& 11) &START&)
display_line In Unknown Protocols : '    ' &V2& - &V1& = (calc &V2& - &V1&)

&set START (calc 40 + &LIDX&)
&set V1 (substr (contents &R1& 12) &START&)
&set V2 (substr (contents &R2& 12) &START&)
display_line Out Octets : '              ' &V2& - &V1& = (calc &V2& - &V1&)

&set START (calc 43 + &LIDX&)
&set V1 (substr (contents &R1& 13) &START&)
&set V2 (substr (contents &R2& 13) &START&)
display_line Out Unicast Packets : '     ' &V2& - &V1& = (calc &V2& - &V1&)

&set START (calc 44 + &LIDX&)
&set V1 (substr (contents &R1& 14) &START&)
&set V2 (substr (contents &R2& 14) &START&)
display_line Out non-Unicast Packets : ' ' &V2& - &V1& = (calc &V2& - &V1&)

&set START (calc 42 + &LIDX&)
&set V1 (substr (contents &R1& 15) &START&)
&set V2 (substr (contents &R2& 15) &START&)
display_line Out Discards : '            ' &V2& - &V1& = (calc &V2& - &V1&)

&set START (calc 40 + &LIDX&)
&set V1 (substr (contents &R1& 16) &START&)
&set V2 (substr (contents &R2& 16) &START&)
display_line Out Errors : '              ' &V2& - &V1& = (calc &V2& - &V1&)

&set START (calc 36 + &LIDX&)
&set V1 (substr (contents &R1& 17) &START&)
&set V2 (substr (contents &R2& 17) &START&)
display_line Out Q Length : '            ' &V2& - &V1& = (calc &V2& - &V1&)
&return
&
&label NOSWITCH
display_line
display_line
<span style="font-family: Courier New,monospace;"display_line &SWITCH& is not responding to SNMP queries using &+
the community string &COMMUNITY&
&return
&
&
&label NOINTERFACE
display_line
display_line
display_line &INTERFACE_NAME& is not an STCP interface on this module
&return
&
&
&label BADMAC
display_line
display_line
display_line MAC address &MAC_ADDR& is not in the format of XX:XX:XX:XX:XX:XX
display_line each octet must be 2 characters
&return
&
&
&label NOTFOUND
display_line
display_line
&if (length &INTERFACE_NAME&) > 0 &then &do
display_line MAC address &MAC_ADDR& for interface &INTERFACE_NAME&
display_line not found in switch &SWITCH&
&end
&else &do
display_line MAC address &MAC_ADDR& not found in switch &SWITCH&
&end
&return
&
&
&label NOIDX
display_line
display_line
display_line No data found for switch port &IDX& in switch &SWITCH&
&
&
& get_switch_interface_stats.cm ends here