|
| 1 | +package probe |
| 2 | + |
| 3 | +import ( |
| 4 | + "strings" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/prometheus/client_golang/prometheus" |
| 8 | + "github.com/prometheus/client_golang/prometheus/testutil" |
| 9 | +) |
| 10 | + |
| 11 | +func TestSwitchHealth(t *testing.T) { |
| 12 | + c := newFakeClient() |
| 13 | + c.prepare("api/v2/monitor/switch-controller/managed-switch/health", "testdata/fsw-health.jsonnet") |
| 14 | + r := prometheus.NewPedanticRegistry() |
| 15 | + if !testProbe(probeSwitchHealth, c, r) { |
| 16 | + t.Errorf("probeSwitchHealth() returned non-success") |
| 17 | + } |
| 18 | + |
| 19 | + em := ` |
| 20 | + # HELP fortiswitch_health_performance_stats_cpu_idle Fortiswitch CPU idle |
| 21 | + # TYPE fortiswitch_health_performance_stats_cpu_idle gauge |
| 22 | + fortiswitch_health_performance_stats_cpu_idle{VDOM="root",fortiswitch="FS00000000000024",unit="%%"} 100 |
| 23 | + fortiswitch_health_performance_stats_cpu_idle{VDOM="root",fortiswitch="FS00000000000027",unit="%%"} 100 |
| 24 | + fortiswitch_health_performance_stats_cpu_idle{VDOM="root",fortiswitch="FS00000000000030",unit="%%"} 100 |
| 25 | + fortiswitch_health_performance_stats_cpu_idle{VDOM="root",fortiswitch="FS00000000000038",unit="%%"} 100 |
| 26 | + # HELP fortiswitch_health_performance_stats_cpu_nice Fortiswitch CPU nice usage |
| 27 | + # TYPE fortiswitch_health_performance_stats_cpu_nice gauge |
| 28 | + fortiswitch_health_performance_stats_cpu_nice{VDOM="root",fortiswitch="FS00000000000024",unit="%%"} 0 |
| 29 | + fortiswitch_health_performance_stats_cpu_nice{VDOM="root",fortiswitch="FS00000000000027",unit="%%"} 0 |
| 30 | + fortiswitch_health_performance_stats_cpu_nice{VDOM="root",fortiswitch="FS00000000000030",unit="%%"} 0 |
| 31 | + fortiswitch_health_performance_stats_cpu_nice{VDOM="root",fortiswitch="FS00000000000038",unit="%%"} 0 |
| 32 | + # HELP fortiswitch_health_performance_stats_cpu_system Fortiswitch CPU system usage |
| 33 | + # TYPE fortiswitch_health_performance_stats_cpu_system gauge |
| 34 | + fortiswitch_health_performance_stats_cpu_system{VDOM="root",fortiswitch="FS00000000000024",unit="%%"} 0 |
| 35 | + fortiswitch_health_performance_stats_cpu_system{VDOM="root",fortiswitch="FS00000000000027",unit="%%"} 0 |
| 36 | + fortiswitch_health_performance_stats_cpu_system{VDOM="root",fortiswitch="FS00000000000030",unit="%%"} 0 |
| 37 | + fortiswitch_health_performance_stats_cpu_system{VDOM="root",fortiswitch="FS00000000000038",unit="%%"} 0 |
| 38 | + # HELP fortiswitch_health_performance_stats_cpu_user Fortiswitch CPU user usage |
| 39 | + # TYPE fortiswitch_health_performance_stats_cpu_user gauge |
| 40 | + fortiswitch_health_performance_stats_cpu_user{VDOM="root",fortiswitch="FS00000000000024",unit="%%"} 0 |
| 41 | + fortiswitch_health_performance_stats_cpu_user{VDOM="root",fortiswitch="FS00000000000027",unit="%%"} 0 |
| 42 | + fortiswitch_health_performance_stats_cpu_user{VDOM="root",fortiswitch="FS00000000000030",unit="%%"} 0 |
| 43 | + fortiswitch_health_performance_stats_cpu_user{VDOM="root",fortiswitch="FS00000000000038",unit="%%"} 0 |
| 44 | + # HELP fortiswitch_health_summary_cpu Summary CPU health |
| 45 | + # TYPE fortiswitch_health_summary_cpu gauge |
| 46 | + fortiswitch_health_summary_cpu{VDOM="root",fortiswitch="FS00000000000024",rating="good"} 0 |
| 47 | + fortiswitch_health_summary_cpu{VDOM="root",fortiswitch="FS00000000000027",rating="good"} 0 |
| 48 | + fortiswitch_health_summary_cpu{VDOM="root",fortiswitch="FS00000000000030",rating="good"} 0 |
| 49 | + fortiswitch_health_summary_cpu{VDOM="root",fortiswitch="FS00000000000038",rating="good"} 0 |
| 50 | + # HELP fortiswitch_health_summary_mem Summary MEM health |
| 51 | + # TYPE fortiswitch_health_summary_mem gauge |
| 52 | + fortiswitch_health_summary_mem{VDOM="root",fortiswitch="FS00000000000024",rating="good"} 10 |
| 53 | + fortiswitch_health_summary_mem{VDOM="root",fortiswitch="FS00000000000027",rating="good"} 15 |
| 54 | + fortiswitch_health_summary_mem{VDOM="root",fortiswitch="FS00000000000030",rating="good"} 50 |
| 55 | + fortiswitch_health_summary_mem{VDOM="root",fortiswitch="FS00000000000038",rating="good"} 32 |
| 56 | + # HELP fortiswitch_health_summary_temp Summary Temperature health |
| 57 | + # TYPE fortiswitch_health_summary_temp gauge |
| 58 | + fortiswitch_health_summary_temp{VDOM="root",fortiswitch="FS00000000000024",rating="good"} 48.952749999999995 |
| 59 | + fortiswitch_health_summary_temp{VDOM="root",fortiswitch="FS00000000000027",rating="good"} 46.156000000000006 |
| 60 | + fortiswitch_health_summary_temp{VDOM="root",fortiswitch="FS00000000000030",rating="good"} 39.71875 |
| 61 | + fortiswitch_health_summary_temp{VDOM="root",fortiswitch="FS00000000000038",rating="good"} 41.624750000000006 |
| 62 | + # HELP fortiswitch_health_summary_uptime Summary Uptime |
| 63 | + # TYPE fortiswitch_health_summary_uptime gauge |
| 64 | + fortiswitch_health_summary_uptime{VDOM="root",fortiswitch="FS00000000000024",rating="good"} 3.928968e+07 |
| 65 | + fortiswitch_health_summary_uptime{VDOM="root",fortiswitch="FS00000000000027",rating="good"} 3.928974e+07 |
| 66 | + fortiswitch_health_summary_uptime{VDOM="root",fortiswitch="FS00000000000030",rating="good"} 2.661288e+07 |
| 67 | + fortiswitch_health_summary_uptime{VDOM="root",fortiswitch="FS00000000000038",rating="good"} 2.661258e+07 |
| 68 | + # HELP fortiswitch_health_temperature Temperature per switch sensor |
| 69 | + # TYPE fortiswitch_health_temperature gauge |
| 70 | + fortiswitch_health_temperature{VDOM="root",fortiswitch="FS00000000000024",module="sensor1(CPU Board Temp)",unit="celsius"} 41.937 |
| 71 | + fortiswitch_health_temperature{VDOM="root",fortiswitch="FS00000000000024",module="sensor2(MAIN Board Temp1)",unit="celsius"} 63.875 |
| 72 | + fortiswitch_health_temperature{VDOM="root",fortiswitch="FS00000000000024",module="sensor3(MAIN Board Temp2)",unit="celsius"} 51.312 |
| 73 | + fortiswitch_health_temperature{VDOM="root",fortiswitch="FS00000000000024",module="sensor4(MAIN Board Temp3)",unit="celsius"} 38.687 |
| 74 | + fortiswitch_health_temperature{VDOM="root",fortiswitch="FS00000000000027",module="sensor1(CPU Board Temp)",unit="celsius"} 39 |
| 75 | + fortiswitch_health_temperature{VDOM="root",fortiswitch="FS00000000000027",module="sensor2(MAIN Board Temp1)",unit="celsius"} 60.625 |
| 76 | + fortiswitch_health_temperature{VDOM="root",fortiswitch="FS00000000000027",module="sensor3(MAIN Board Temp2)",unit="celsius"} 48.937 |
| 77 | + fortiswitch_health_temperature{VDOM="root",fortiswitch="FS00000000000027",module="sensor4(MAIN Board Temp3)",unit="celsius"} 36.062 |
| 78 | + fortiswitch_health_temperature{VDOM="root",fortiswitch="FS00000000000030",module="sensor1(CPU Board Temp)",unit="celsius"} 33.875 |
| 79 | + fortiswitch_health_temperature{VDOM="root",fortiswitch="FS00000000000030",module="sensor2(MAIN Board Temp1)",unit="celsius"} 53.75 |
| 80 | + fortiswitch_health_temperature{VDOM="root",fortiswitch="FS00000000000030",module="sensor3(MAIN Board Temp2)",unit="celsius"} 41 |
| 81 | + fortiswitch_health_temperature{VDOM="root",fortiswitch="FS00000000000030",module="sensor4(MAIN Board Temp3)",unit="celsius"} 30.25 |
| 82 | + fortiswitch_health_temperature{VDOM="root",fortiswitch="FS00000000000038",module="sensor1(CPU Board Temp)",unit="celsius"} 35.437 |
| 83 | + fortiswitch_health_temperature{VDOM="root",fortiswitch="FS00000000000038",module="sensor2(MAIN Board Temp1)",unit="celsius"} 55.625 |
| 84 | + fortiswitch_health_temperature{VDOM="root",fortiswitch="FS00000000000038",module="sensor3(MAIN Board Temp2)",unit="celsius"} 43.125 |
| 85 | + fortiswitch_health_temperature{VDOM="root",fortiswitch="FS00000000000038",module="sensor4(MAIN Board Temp3)",unit="celsius"} 32.312 |
| 86 | + ` |
| 87 | + if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil { |
| 88 | + t.Fatalf("metric compare: err %v", err) |
| 89 | + } |
| 90 | +} |
0 commit comments