Skip to content

Commit

Permalink
non db mood added
Browse files Browse the repository at this point in the history
Signed-off-by: sayedppqq <[email protected]>
  • Loading branch information
sayedppqq committed May 17, 2024
1 parent 4bc6cca commit 5450ebc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
4 changes: 3 additions & 1 deletion pkg/cmds/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,15 @@ func DashboardCMD(f cmdutil.Factory) *cobra.Command {
branch string
file string
url string
nonDB bool
)
cmd := &cobra.Command{
Use: "dashboard",
Short: i18n.T("Check availability of a grafana dashboard"),
Long: dashboardLong,

Run: func(cmd *cobra.Command, args []string) {
dashboard.Run(f, args, branch, file, url, prom)
dashboard.Run(f, args, branch, file, url, prom, nonDB)
},
Example: dashboardExample,
DisableFlagsInUseLine: true,
Expand All @@ -183,6 +184,7 @@ func DashboardCMD(f cmdutil.Factory) *cobra.Command {
cmd.Flags().StringVarP(&file, "file", "f", "", "absolute or relative path of the file containing dashboard")
cmd.Flags().StringVarP(&url, "url", "u", "", "url of the raw file containing dashboard. "+
"For example: https://raw.githubusercontent.com/appscode/grafana-dashboards/master/mongodb/mongodb-summary-dashboard.json")
cmd.Flags().BoolVarP(&nonDB, "nondb", "o", false, "for non db object's. just provide the url")
return cmd
}

Expand Down
50 changes: 32 additions & 18 deletions pkg/monitor/dashboard/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package dashboard
import (
"context"
"fmt"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"log"
"strings"
"time"
Expand All @@ -40,25 +41,34 @@ type missingOpts struct {
panelTitle []string
}

func Run(f cmdutil.Factory, args []string, branch, file, url string, prom monitor.PromSvc) {
if len(args) < 2 {
log.Fatal("Enter db object's name as an argument")
}
database := monitor.ConvertedResourceToPlural(args[0])
dbName := args[1]
namespace, _, err := f.ToRawKubeConfigLoader().Namespace()
if err != nil {
_ = fmt.Errorf("failed to get current namespace")
return
}
func Run(f cmdutil.Factory, args []string, branch, file, url string, prom monitor.PromSvc, nonDB bool) {
var (
db *unstructured.Unstructured
database string
namespace string
dbName string
err error
)
if !nonDB {
if len(args) < 2 {
log.Fatal("Enter db object's name as an argument")
}
database = monitor.ConvertedResourceToPlural(args[0])
dbName = args[1]
namespace, _, err = f.ToRawKubeConfigLoader().Namespace()
if err != nil {
_ = fmt.Errorf("failed to get current namespace")
return
}

db, err := getDB(f, database, namespace, dbName)
if err != nil {
fmt.Printf("failed to get %s database %s/%s. error %s \n", database, namespace, dbName, err.Error())
return
}
db, err = getDB(f, database, namespace, dbName)
if err != nil {
fmt.Printf("failed to get %s database %s/%s. error %s \n", database, namespace, dbName, err.Error())
return
}

database = monitor.ConvertedResourceToSingular(database)
database = monitor.ConvertedResourceToSingular(database)
}
var dashboardData map[string]interface{}
if file == "" {
if url == "" { // fetch from appscode/grafana-dashboard repo
Expand Down Expand Up @@ -137,7 +147,11 @@ func Run(f cmdutil.Factory, args []string, branch, file, url string, prom monito
}
fmt.Printf("Effected Panel: %s \n", strings.Join(opts.panelTitle, ", "))
}
log.Fatalf("Mission information found in dashboard in Database %s: %s/%s\n", database, namespace, dbName)
if !nonDB {
log.Fatalf("Mission information found in dashboard in Database %s: %s/%s\n", database, namespace, dbName)
} else {
log.Fatalf("Mission information found")
}
} else {
fmt.Println("All metrics found")
}
Expand Down

0 comments on commit 5450ebc

Please sign in to comment.