New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
list web scenarios as well as web items #4
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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,50 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
// HTTPTestStep represents single step in the web scenario. | ||
type HTTPTestStep struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you please add doc to this structures? they have ambigious names (associated with some test purposes for me) |
||
ID string `json:"httpstepid"` | ||
TestID string `json:"httptestid"` | ||
URL string `json:"url"` | ||
} | ||
|
||
// HTTPTest represents web scenario, which often used for simple step-by-step | ||
// external monitoring of websites via HTTP. | ||
type HTTPTest struct { | ||
ID string `json:"httptestid"` | ||
HostID string `json:"hostid"` | ||
Name string `json:"name"` | ||
Delay string `json:"delay"` | ||
NextCheck string `json:"nextcheck"` | ||
TemplateID string `json:"templateid"` | ||
|
||
Steps []HTTPTestStep `json:"steps"` | ||
} | ||
|
||
func (check *HTTPTest) DateTime() string { | ||
if check.NextCheck == "0" { | ||
return "-" | ||
} | ||
|
||
return check.date().Format("2006-01-02 15:04:05") | ||
} | ||
|
||
func (check *HTTPTest) date() time.Time { | ||
date, _ := strconv.ParseInt(check.NextCheck, 10, 64) | ||
return time.Unix(date, 0) | ||
} | ||
|
||
func (check *HTTPTest) Format() string { | ||
return fmt.Sprintf( | ||
"%s (%d steps every %s seconds)\t%s (next)\t", | ||
check.Name, | ||
len(check.Steps), | ||
check.Delay, | ||
check.DateTime(), | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"strconv" | ||
) | ||
|
||
type ItemType int | ||
|
||
const ( | ||
ItemTypeAgent ItemType = iota | ||
ItemTypeSNMPv1 | ||
ItemTypeTrapper | ||
ItemTypeSimpleCheck | ||
ItemTypeSNMPv2 | ||
ItemTypeInternal | ||
ItemTypeSNMPv3 | ||
ItemTypeAgentActive | ||
ItemTypeAggregate | ||
ItemTypeWeb | ||
ItemTypeExternalCheck | ||
ItemTypeDatabaseMonitor | ||
ItemTypeIPMI | ||
ItemTypeSSH | ||
ItemTypeTELNET | ||
ItemTypeCalculated | ||
ItemTypeJMX | ||
ItemTypeSNMPTrap | ||
) | ||
|
||
func (type_ *ItemType) UnmarshalJSON(data []byte) error { | ||
var stringValue string | ||
|
||
err := json.Unmarshal(data, &stringValue) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
intValue, err := strconv.ParseInt(stringValue, 10, 64) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
*type_ = ItemType(intValue) | ||
|
||
return nil | ||
} | ||
|
||
func (type_ ItemType) String() string { | ||
switch type_ { | ||
case ItemTypeAgent: | ||
return "agent" | ||
case ItemTypeTrapper: | ||
return "trapper" | ||
case ItemTypeSimpleCheck: | ||
return "check" | ||
case ItemTypeSNMPv2: | ||
return "snmp2" | ||
case ItemTypeInternal: | ||
return "internal" | ||
case ItemTypeSNMPv3: | ||
return "snmp3" | ||
case ItemTypeAgentActive: | ||
return "active" | ||
case ItemTypeAggregate: | ||
return "aggregate" | ||
case ItemTypeWeb: | ||
return "web" | ||
case ItemTypeExternalCheck: | ||
return "external" | ||
case ItemTypeDatabaseMonitor: | ||
return "dbmon" | ||
case ItemTypeIPMI: | ||
return "ipmi" | ||
case ItemTypeSSH: | ||
return "ssh" | ||
case ItemTypeTELNET: | ||
return "telnet" | ||
case ItemTypeCalculated: | ||
return "calc" | ||
case ItemTypeJMX: | ||
return "jmx" | ||
case ItemTypeSNMPTrap: | ||
return "snmp" | ||
default: | ||
return "unknown" | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just
for err := range errs
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am talking about the second part of
range
, why there is such ambigious statement as[]error{<-errs, <-errs}
, why not justrange errs
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kovetskiy: because
range errs
will never end. Range over channel waits till channel is closed, which will never happen in that case.