5
5
from copy import deepcopy
6
6
from operator import attrgetter
7
7
8
+ from sqlalchemy import false
9
+ from sqlalchemy .orm .base import instance_dict
10
+
8
11
# Application imports
9
12
from switchmap .core import log
10
13
from switchmap .core import general
@@ -529,9 +532,15 @@ def macport(self, test=False):
529
532
# Initialize variables
530
533
valid_mac = None
531
534
532
- # Create lowercase version of MAC address
535
+ # Normalize possible bytes OctetString to hex
536
+ raw_mac = (
537
+ next_mac .hex ()
538
+ if isinstance (next_mac , (bytes , bytearray ))
539
+ else next_mac
540
+ )
541
+
533
542
# Handle double-encoded MAC addresses from async poller
534
- decoded_mac = decode_mac_address (next_mac )
543
+ decoded_mac = decode_mac_address (raw_mac )
535
544
mactest = general .mac (decoded_mac )
536
545
if bool (mactest .valid ) is False :
537
546
continue
@@ -613,8 +622,18 @@ def ipport(self, test=False):
613
622
614
623
# Iterate over the MACs found
615
624
for item in sorted (_macs ):
625
+ # Normalize possible bytes OctetString to hex and decode
626
+ raw_mac = (
627
+ item .hex ()
628
+ if isinstance (item , (bytes , bytearray ))
629
+ else item
630
+ )
631
+ decoded = decode_mac_address (raw_mac )
632
+ mtest = general .mac (decoded )
633
+ if bool (mtest .valid ) is False :
634
+ continue
616
635
# Ensure the MAC exists in the database
617
- mac_exists = _mac .exists (self ._device .idx_zone , item )
636
+ mac_exists = _mac .exists (self ._device .idx_zone , mtest . mac )
618
637
if bool (mac_exists ) is True :
619
638
# Get all the IP addresses for the mac
620
639
found = _macip .idx_ips_exist (mac_exists .idx_mac )
@@ -664,24 +683,43 @@ def systemstat(self, test=False):
664
683
# Log start
665
684
self .log ("SystemStat" )
666
685
667
- # Extract CISCO MIB data from system section
686
+ # Extract vendor-specific MIB data from system section
668
687
system_data = self ._data .get ("system" , {})
669
688
670
- # Get CPU data from CISCO-PROCESS-MIB
689
+ # Initialize variables
671
690
cpu_5min = None
672
- cisco_process = system_data .get ("CISCO-PROCESS-MIB" , {})
673
- cpu_total_5min = cisco_process .get ("cpmCPUTotal5minRev" , {})
674
- if cpu_total_5min :
675
- # Get the first CPU value (usually CPU '1')
676
- cpu_5min = next (iter (cpu_total_5min .values ()), None )
677
-
678
- # Get Memory data from CISCO-MEMORY-POOL-MIB
679
691
mem_used = None
680
692
mem_free = None
681
- cisco_memory = system_data .get ("CISCO-MEMORY-POOL-MIB" , {})
682
- if cisco_memory :
683
- mem_used = cisco_memory .get ("ciscoMemoryPoolUsed" )
684
- mem_free = cisco_memory .get ("ciscoMemoryPoolFree" )
693
+
694
+ # Get CPU and Memory data from CISCO-PROCESS-MIB
695
+ cisco_process = system_data .get ("CISCO-PROCESS-MIB" , {})
696
+ if cisco_process :
697
+ # Get CPU data
698
+ cpu_total_5min = cisco_process .get ("cpmCPUTotal5minRev" , {})
699
+ if cpu_total_5min :
700
+ # Get the first CPU value (usually CPU '1')
701
+ cpu_5min = next (iter (cpu_total_5min .values ()), None )
702
+
703
+ # Get Memory data from CISCO-PROCESS-MIB
704
+ if not mem_used :
705
+ mem_used = cisco_process .get ("ciscoMemoryPoolUsed" )
706
+ if not mem_free :
707
+ mem_free = cisco_process .get ("ciscoMemoryPoolFree" )
708
+
709
+ # Get CPU and Memory data from JUNIPER-MIB
710
+ juniper_process = system_data .get ("JUNIPER-MIB" , {})
711
+ if juniper_process :
712
+ # Get CPU data
713
+ juniper_cpu = juniper_process .get ("jnxOperatingCPU" , {})
714
+ if juniper_cpu and cpu_5min is None :
715
+ # Get the first CPU value
716
+ cpu_5min = next (iter (juniper_cpu .values ()), None )
717
+
718
+ # Get Memory data
719
+ if not mem_used :
720
+ mem_used = juniper_process .get ("jnxOperatingMemoryUsed" )
721
+ if not mem_free :
722
+ mem_free = juniper_process .get ("jnxOperatingMemoryFree" )
685
723
686
724
# Only create record if we have some data
687
725
if cpu_5min is not None or mem_used is not None or mem_free is not None :
@@ -701,8 +739,8 @@ def systemstat(self, test=False):
701
739
else :
702
740
# Insert new record
703
741
if not test :
704
- _systemstat .insert_row (inserts )
705
- # Log completion
742
+ _systemstat .insert_row (row )
743
+
706
744
self .log ("SystemStat" , updated = True )
707
745
708
746
# Mark as completed
0 commit comments