-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a command to interact with the diagnostic rpc
This wil allow to query the diagnostic state of the device and also to query the filter schema from the device. Signed-off-by: Christian Ege <[email protected]>
- Loading branch information
Showing
3 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
Copyright © 2023 Christian Ege <[email protected]> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/graugans/go-ovp8xx/pkg/ovp8xx" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func diagnosticGetFilteredCommand(cmd *cobra.Command, args []string) error { | ||
|
||
filter, err := cmd.Flags().GetString("filter") | ||
if err != nil { | ||
return err | ||
} | ||
host, err := rootCmd.PersistentFlags().GetString("ip") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
o3r := ovp8xx.NewClient( | ||
ovp8xx.WithHost(host), | ||
) | ||
|
||
diag := o3r.GetDiagnosticClient() | ||
result, err := diag.GetFiltered( | ||
*ovp8xx.NewConfig( | ||
ovp8xx.WitJSONString(filter), | ||
), | ||
) | ||
if err != nil { | ||
return err | ||
} else { | ||
fmt.Printf("%s\n", result) | ||
} | ||
return nil | ||
} | ||
|
||
func diagnosticGetFilterSchemaCommand(cmd *cobra.Command, args []string) error { | ||
|
||
host, err := rootCmd.PersistentFlags().GetString("ip") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
o3r := ovp8xx.NewClient( | ||
ovp8xx.WithHost(host), | ||
) | ||
|
||
diag := o3r.GetDiagnosticClient() | ||
result, err := diag.GetFilterSchema() | ||
if err != nil { | ||
return err | ||
} else { | ||
fmt.Printf("%s\n", result) | ||
} | ||
return nil | ||
} | ||
|
||
var diagnosticCmd = &cobra.Command{ | ||
Use: "diagnostic", | ||
Short: "Interact with diagnostic subsystem of the OVP8xx", | ||
} | ||
|
||
var diagnosticGetFilteredCmd = &cobra.Command{ | ||
Use: "getFiltered", | ||
Short: "Retrieve the filtered diagnostic JSON from the device", | ||
RunE: diagnosticGetFilteredCommand, | ||
} | ||
|
||
var diagnosticGetFilterSchemaCmd = &cobra.Command{ | ||
Use: "getFilterSchema", | ||
Short: "Retrieve the diagnostic filter schema JSON from the device", | ||
RunE: diagnosticGetFilterSchemaCommand, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(diagnosticCmd) | ||
diagnosticCmd.AddCommand(diagnosticGetFilteredCmd) | ||
diagnosticCmd.AddCommand(diagnosticGetFilterSchemaCmd) | ||
diagnosticGetFilteredCmd.Flags().String("filter", "{\"state\": \"active\"}", "A JSON filter representation") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters