Rewrite in Golang#2
Conversation
Co-authored-by: Christoph Breit <christoph.breit@netways.de>
| } | ||
|
|
||
| // checkContent compares the file content against the given thresholds | ||
| func checkContent(fileContent string, warningThreshold check.Threshold, criticalThreshold check.Threshold) *result.PartialResult { |
There was a problem hiding this comment.
This function should return an unknown if the file content is not a statfile
echo "foobar" > /tmp/status
go run main.go --statusfile /tmp/status
[CRITICAL] - Registered on network '' with signal strength 0%
\_ [OK] Status file was last updated 6 seconds ago
\_ [CRITICAL] Registered on network '' with signal strength 0%
|dbm=-113 signal=0%;40:;20: bit_error_rate=0
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| var warning, critical, statusfilePath string |
There was a problem hiding this comment.
Please put those variables in a config struct so it obvious that they belong together and share a purpose.
| var csqRe = regexp.MustCompile(`\+CSQ:\s*(\d+),(\d+)`) | ||
| var copsReQuoted = regexp.MustCompile(`\+COPS:\s*\d+,\d+,"([^"]*)"`) | ||
| var copsReUnquoted = regexp.MustCompile(`\+COPS:\s*\d+,\d+,([^"]+)`) | ||
| var cregRe = regexp.MustCompile(`\+CREG:\s*(\d,(?:1|5))`) |
There was a problem hiding this comment.
Could those be constants?
|
|
||
| var rootCmd = &cobra.Command{ | ||
| Use: "check_sms3status", | ||
| Short: "This plugin checks the status of an SMS modem using the regular_run functionality provided in smstools3", |
There was a problem hiding this comment.
I think some prefix for "plugin" would be good. What kind of "plugin" is it? For what?
Assume someone might find this without a big Icinga/Nagios/Naemon background.
|
|
||
| var fileInfo os.FileInfo | ||
|
|
||
| if contentErr != nil { |
There was a problem hiding this comment.
The error check should be directly below the statement that might cause the error.
| val, err := strconv.Atoi(matches[1]) | ||
| if err == nil { | ||
| signal = val | ||
| } |
There was a problem hiding this comment.
If there is no match for the regex, signal is just zero. Is that correct?
|
|
||
| msg := fmt.Sprintf("Registered on network '%s' with signal strength %0.f%%", network, sigproc) | ||
|
|
||
| result.Output = msg |
There was a problem hiding this comment.
why not just result.Output = fmt.Sprinf....?
|
Why move the files to the |
True. We've done this before, I think so that the old code is more visible. We can still remove it at some point |
No description provided.