예제 #1
0
func HealthHandler(rw http.ResponseWriter, request *http.Request) error {
	rw.Header().Set("Content-Type", "application/json")

	ok := clair.IsHealthy()
	if !ok {
		rw.WriteHeader(http.StatusServiceUnavailable)
	}

	healthBody := health{
		Clair: ok,
	}

	j, err := healthBody.asJSON()
	if err != nil {
		return err
	}
	fmt.Fprint(rw, j)
	return nil
}
예제 #2
0
	"github.com/wemanity-belgium/hyperclair/clair"
	"github.com/wemanity-belgium/hyperclair/xerrors"
)

const healthTplt = `
Clair: {{if .}}✔{{else}}✘{{end}}
`

type health struct {
	Clair interface{} `json:"clair"`
}

var healthCmd = &cobra.Command{
	Use:   "health",
	Short: "Get Health of Hyperclair and underlying services",
	Long:  `Get Health of Hyperclair and underlying services`,
	Run: func(cmd *cobra.Command, args []string) {
		ok := clair.IsHealthy()
		err := template.Must(template.New("health").Parse(healthTplt)).Execute(os.Stdout, ok)
		if err != nil {
			fmt.Println(xerrors.InternalError)
			logrus.Fatalf("rendering the health: %v", err)
		}

	},
}

func init() {
	RootCmd.AddCommand(healthCmd)
}