github.com/fafucoder/cilium@v1.6.11/cilium/cmd/endpoint_healthz.go (about) 1 // Copyright 2017 Authors of Cilium 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package cmd 16 17 import ( 18 "fmt" 19 "os" 20 "text/tabwriter" 21 22 "github.com/cilium/cilium/pkg/command" 23 24 "github.com/spf13/cobra" 25 ) 26 27 // endpointHealthCmd represents the endpoint_healthz command 28 var endpointHealthCmd = &cobra.Command{ 29 Use: "health <endpoint id>", 30 Short: "View endpoint health", 31 Example: "cilium endpoint health 5421", 32 Run: func(cmd *cobra.Command, args []string) { 33 requireEndpointID(cmd, args) 34 getEndpointHealth(cmd, args) 35 }, 36 } 37 38 func init() { 39 endpointCmd.AddCommand(endpointHealthCmd) 40 command.AddJSONOutput(endpointHealthCmd) 41 } 42 43 func getEndpointHealth(cmd *cobra.Command, args []string) { 44 requireEndpointID(cmd, args) 45 eID := args[0] 46 epHealth, err := client.EndpointHealthGet(eID) 47 if err != nil { 48 Fatalf("Cannot get endpoint healthz %s: %s\n", eID, err) 49 } 50 51 if command.OutputJSON() { 52 if err := command.PrintOutput(epHealth); err != nil { 53 os.Exit(1) 54 } 55 } else { 56 w := tabwriter.NewWriter(os.Stdout, 2, 0, 3, ' ', 0) 57 fmt.Fprintf(w, "Overall Health:\t%s\n", epHealth.OverallHealth) 58 fmt.Fprintf(w, "BPF Health:\t%s\n", epHealth.Bpf) 59 fmt.Fprintf(w, "Policy Health:\t%s\n", epHealth.Policy) 60 connected := map[bool]string{true: "yes", false: "no"} 61 fmt.Fprintf(w, "Connected:\t%s\n", connected[epHealth.Connected]) 62 w.Flush() 63 } 64 }