Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from seletskiy/web-scenarios
list web scenarios as well as web items
- Loading branch information
Showing
6 changed files
with
216 additions
and
16 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
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 { | ||
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