Skip to content

Commit

Permalink
Add health check option
Browse files Browse the repository at this point in the history
  • Loading branch information
RamanaReddy0M committed Feb 22, 2024
1 parent 974deba commit c27bba7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ type Options struct {
Silent bool
Verbose bool
Debug bool
HealthCheck bool
}
7 changes: 7 additions & 0 deletions pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func ParseOptions() *Options {
flagset.BoolVar(&options.Silent, "silent", false, "Silent"),
flagset.BoolVar(&options.Verbose, "verbose", false, "Verbose"),
flagset.BoolVar(&options.Debug, "debug", false, "Debug"),
flagset.BoolVarP(&options.HealthCheck, "health-check", "hc", false, "run diagnostic check up"),
)

if err := flagset.Parse(); err != nil {
Expand All @@ -160,6 +161,12 @@ func ParseOptions() *Options {
os.Exit(0)
}

if options.HealthCheck {
showBanner()
gologger.Print().Msgf("%s\n", DoHealthCheck(options))
os.Exit(0)
}

// api key hierarchy: cli flag > env var > .pdcp/credential file
if options.PdcpAuth == "true" {
AuthWithPDCP()
Expand Down
34 changes: 34 additions & 0 deletions pkg/runner/util.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,48 @@
package runner

import (
"fmt"
"net"
"os"
"os/exec"
"runtime"
"strings"

"github.com/projectdiscovery/cvemap/pkg/types"
fileutil "github.com/projectdiscovery/utils/file"
)

func DoHealthCheck(opts Options) string {
var test strings.Builder
test.WriteString(fmt.Sprintf("Version: %s\n", Version))
test.WriteString(fmt.Sprintf("Operating System: %s\n", runtime.GOOS))
test.WriteString(fmt.Sprintf("Architecture: %s\n", runtime.GOARCH))
test.WriteString(fmt.Sprintf("Go Version: %s\n", runtime.Version()))
test.WriteString(fmt.Sprintf("Compiler: %s\n", runtime.Compiler))

var testResult string
c4, err := net.Dial("tcp4", "cve.projectdiscovery.io:443")
if err == nil && c4 != nil {
c4.Close()
}
testResult = "Ok"
if err != nil {
testResult = fmt.Sprintf("Ko (%s)", err)
}
test.WriteString(fmt.Sprintf("IPv4 connectivity to cve.projectdiscovery.io:443 => %s\n", testResult))

u4, err := net.Dial("udp4", "cve.projectdiscovery.io:53")
if err == nil && u4 != nil {
u4.Close()
}
testResult = "Ok"
if err != nil {
testResult = fmt.Sprintf("Ko (%s)", err)
}
test.WriteString(fmt.Sprintf("IPv4 UDP connectivity to cve.projectdiscovery.io:53 => %s\n", testResult))
return test.String()
}

func getLatestVersionCVSSScore(cvss types.CvssMetrics) float64 {
var highestScore float64
if cvss.Cvss2 != nil {
Expand Down

0 comments on commit c27bba7

Please sign in to comment.