Skip to content

Commit 2136271

Browse files
HOS-24599: Implement AH_MSG_TRAP_BOOTOS trap over telegraf
1 parent b10c26b commit 2136271

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

plugins/inputs/ah_trap/ah_trap.go

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,56 @@ func (t *TrapPlugin) Gather_Ah_send_trap(trapType uint32, trapBuf [256]byte, acc
378378
"powerMode_poeTrap": powerModeToString(poe.PowerMode),
379379
}, nil)
380380

381+
case AH_MSG_TRAP_BOOTOS:
382+
var bootos AhTgrafBootOsTrap
383+
copy((*[unsafe.Sizeof(bootos)]byte)(unsafe.Pointer(&bootos))[:], trapBuf[:unsafe.Sizeof(bootos)])
384+
385+
acc.AddFields("TrapEvent", map[string]interface{}{
386+
"trapId_bootosTrap": bootos.TrapID,
387+
"osType_bootosTrap": osTypeToString(bootos.OsType),
388+
"status_bootosTrap": bootosStatusToString(bootos.Status),
389+
"description_bootosTrap": ahutil.CleanCString(bootos.Description[:]),
390+
}, nil)
391+
381392
}
382393

383394
return nil
384395
}
385396

397+
/*
398+
Helper function to convert osType value to string for bootos trap
399+
*/
400+
func osTypeToString(osType uint8) string {
401+
switch osType {
402+
case 0:
403+
return "HOS"
404+
case 1:
405+
return "WiNG"
406+
case 2:
407+
return "WiNG-CAMP"
408+
case 3:
409+
return "WiNG-DIST"
410+
default:
411+
return fmt.Sprintf("UNKNOWN(%d)", osType)
412+
}
413+
}
414+
415+
/*
416+
Helper function to convert bootos status value to string
417+
*/
418+
func bootosStatusToString(status uint8) string {
419+
switch status {
420+
case 0:
421+
return "Success"
422+
case 1:
423+
return "Failed"
424+
case 2:
425+
return "Legacy HW"
426+
default:
427+
return fmt.Sprintf("UNKNOWN(%d)", status)
428+
}
429+
}
430+
386431
/*
387432
Helper function to convert powerMode value to string
388433
*/
@@ -565,7 +610,19 @@ func (t *TrapPlugin) trapListener(conn net.PacketConn) {
565610
if err := t.Gather_Ah_send_trap(trapType, trapBuf, t.acc); err != nil {
566611
log.Printf("[ah_trap] Error gathering Poe trap: %v", err)
567612
}
568-
}
613+
case AH_MSG_TRAP_BOOTOS:
614+
var bootos AhTgrafBootOsTrap
615+
expected := int(unsafe.Sizeof(bootos))
616+
if len(payload) != expected {
617+
log.Printf("[ah_trap] Invalid Bootos size: got %d, expected %d", len(payload), expected)
618+
continue
619+
}
620+
var trapBuf [AH_TRAP_SIZE_256]byte
621+
copy(trapBuf[:expected], payload)
622+
if err := t.Gather_Ah_send_trap(trapType, trapBuf, t.acc); err != nil {
623+
log.Printf("[ah_trap] Error gathering Bootos trap: %v", err)
624+
}
625+
}
569626
}
570627
}
571628

plugins/inputs/ah_trap/ah_trap_defines_common.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const (
3030
AH_TRAP_SIZE_300 = 300
3131
AH_TRAP_SIZE_256 = 256
3232
AH_MSG_TRAP_POE = 16
33+
AH_MSG_TRAP_BOOTOS = 121
3334
)
3435

3536
const (
@@ -96,6 +97,13 @@ type AhTgrafPoeTrap struct {
9697
PowerMode uint8
9798
}
9899

100+
type AhTgrafBootOsTrap struct {
101+
TrapID uint8
102+
OsType uint8
103+
Status uint8
104+
Description [TRAP_DCRPT_LEN]byte
105+
}
106+
99107
type AhFailureTrap struct {
100108
Name [AH_MAX_TRAP_OBJ_NAME+1]byte
101109
Cause int32

0 commit comments

Comments
 (0)