Skip to content

Commit

Permalink
[RFE] close #137
Browse files Browse the repository at this point in the history
  • Loading branch information
gmeghnag committed Mar 7, 2024
1 parent 15eb985 commit 521524a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
38 changes: 38 additions & 0 deletions cmd/node-logs/node-logs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package nodelogs

import (
"fmt"
"os"
"strings"

"github.com/gmeghnag/omc/vars"
"github.com/spf13/cobra"
)

// alertCmd represents the alert command
var NodeLogs = &cobra.Command{
Use: "node-logs",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
fmt.Println("The following node services logs are available to be read:")
fmt.Println("")
files, _ := os.ReadDir(vars.MustGatherRootPath + "/host_service_logs/masters/")
for _, f := range files {
fmt.Println("-", strings.TrimSuffix(f.Name(), "_service.log"))
}
fmt.Println("\nis it possible to read the content by executing 'omc node-logs <SERVICE>'.")
}
if len(args) > 1 {
fmt.Fprintln(os.Stderr, "Expect zero arguemnt, found: ", len(args))
os.Exit(1)
}
if len(args) == 1 {
text, err := os.ReadFile(vars.MustGatherRootPath + "/host_service_logs/masters/" + args[0] + "_service.log")
if err != nil {
fmt.Fprintln(os.Stderr, "logs for service \""+args[0]+"\" not found or readable.")
os.Exit(1)
}
fmt.Print(string(text))
}
},
}
2 changes: 2 additions & 0 deletions root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/gmeghnag/omc/cmd/helpers"
"github.com/gmeghnag/omc/cmd/logs"
"github.com/gmeghnag/omc/cmd/machineconfig"
nodelogs "github.com/gmeghnag/omc/cmd/node-logs"
"github.com/gmeghnag/omc/cmd/ovn"
"github.com/gmeghnag/omc/cmd/prometheus"
"github.com/gmeghnag/omc/cmd/upgrade"
Expand Down Expand Up @@ -94,6 +95,7 @@ func init() {
use.UseCmd,
cmd.MustGather,
cmd.IngestCRDS,
nodelogs.NodeLogs,
config.ConfigCmd,
get.GetCmd,
describe.DescribeCmd,
Expand Down

0 comments on commit 521524a

Please sign in to comment.