|
| 1 | +/* |
| 2 | +Copyright © 2021 NAME HERE <EMAIL ADDRESS> |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | +package cmd |
| 17 | + |
| 18 | +import ( |
| 19 | + "github.com/spf13/cobra" |
| 20 | + "onyxiactl/utils" |
| 21 | +) |
| 22 | + |
| 23 | +func init() { |
| 24 | + rootCmd.AddCommand(healthCmd) |
| 25 | +} |
| 26 | + |
| 27 | +var healthCmd = &cobra.Command{ |
| 28 | + Use: "health", |
| 29 | + Aliases: []string{"ping"}, |
| 30 | + Short: "Ping the provider.", |
| 31 | + Long: `Call the healthcheck URL.`, |
| 32 | + Run: func(cmd *cobra.Command, args []string) { health(cmd) }, |
| 33 | +} |
| 34 | + |
| 35 | +func health(cmd *cobra.Command) error { |
| 36 | + onyxiaURL, _ := cmd.Flags().GetString("onyxiaURL") |
| 37 | + |
| 38 | + _, e := utils.CallAPIGet(onyxiaURL+"/public/healthcheck", "") |
| 39 | + if e != nil { |
| 40 | + utils.PrintErrorAndExit("CRIT: provider is NOT healthy, " + e.Error() + ".") |
| 41 | + } |
| 42 | + |
| 43 | + utils.PrintMessage("OK: provider is healthy.") |
| 44 | + return nil |
| 45 | +} |
0 commit comments