Skip to content

Commit

Permalink
Merge pull request #17 from inexio/dev
Browse files Browse the repository at this point in the history
Dev into main
  • Loading branch information
toberd authored Mar 4, 2021
2 parents 8fa0505 + 055c76d commit ab00db2
Show file tree
Hide file tree
Showing 22 changed files with 621 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ Use the `identify` mode to automatically discover some properties of a network d
$ thola identify

Usage:
thola identify [flags]
Specify the address of the network device using the `--ip` flag.
thola identify [host] [flags]
Specify the address of the network device in the `[host]` argument.
The `--format` flag modifies the format of the output. `--format pretty` is set by default and is useful when reading the output manually. Other options are `json` and `xml`.

$ thola identify 10.204.2.90
Expand Down
78 changes: 78 additions & 0 deletions api/request_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,33 @@ func StartAPI() {
// $ref: '#/definitions/OutputError'
e.POST("/check/sbc", checkSBC)

// swagger:operation POST /check/server check checkServer
// ---
// summary: Check a linux server.
// consumes:
// - application/json
// - application/xml
// produces:
// - application/json
// - application/xml
// parameters:
// - name: body
// in: body
// description: Request to process.
// required: true
// schema:
// $ref: '#/definitions/CheckServerRequest'
// responses:
// 200:
// description: Returns the response.
// schema:
// $ref: '#/definitions/CheckServerResponse'
// 400:
// description: Returns an error with more details in the body.
// schema:
// $ref: '#/definitions/OutputError'
e.POST("/check/server", checkServer)

// swagger:operation POST /check/hardware-health check checkSBC
// ---
// summary: Check an hardware health of an device.
Expand Down Expand Up @@ -501,6 +528,33 @@ func StartAPI() {
// $ref: '#/definitions/OutputError'
e.POST("/read/sbc", readSBC)

// swagger:operation POST /read/server read readServer
// ---
// summary: Reads out server data of a device.
// consumes:
// - application/json
// - application/xml
// produces:
// - application/json
// - application/xml
// parameters:
// - name: body
// in: body
// description: Request to process.
// required: true
// schema:
// $ref: '#/definitions/ReadServerRequest'
// responses:
// 200:
// description: Returns the response.
// schema:
// $ref: '#/definitions/ReadServerResponse'
// 400:
// description: Returns an error with more details in the body.
// schema:
// $ref: '#/definitions/OutputError'
e.POST("/read/server", readServer)

// swagger:operation POST /read/hardware-health read hardware health
// ---
// summary: Reads out hardware health data of a device.
Expand Down Expand Up @@ -699,6 +753,18 @@ func checkSBC(ctx echo.Context) error {
return returnInFormat(ctx, http.StatusOK, resp)
}

func checkServer(ctx echo.Context) error {
r := request.CheckServerRequest{}
if err := ctx.Bind(&r); err != nil {
return err
}
resp, err := handleAPIRequest(ctx, &r, &r.BaseRequest.DeviceData.IPAddress)
if err != nil {
return handleError(ctx, err)
}
return returnInFormat(ctx, http.StatusOK, resp)
}

func checkHardwareHealth(ctx echo.Context) error {
r := request.CheckHardwareHealthRequest{}
if err := ctx.Bind(&r); err != nil {
Expand Down Expand Up @@ -783,6 +849,18 @@ func readSBC(ctx echo.Context) error {
return returnInFormat(ctx, http.StatusOK, resp)
}

func readServer(ctx echo.Context) error {
r := request.ReadServerRequest{}
if err := ctx.Bind(&r); err != nil {
return err
}
resp, err := handleAPIRequest(ctx, &r, &r.BaseRequest.DeviceData.IPAddress)
if err != nil {
return handleError(ctx, err)
}
return returnInFormat(ctx, http.StatusOK, resp)
}

func readHardwareHealth(ctx echo.Context) error {
r := request.ReadHardwareHealthRequest{}
if err := ctx.Bind(&r); err != nil {
Expand Down
24 changes: 24 additions & 0 deletions cmd/check_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cmd

import (
"github.com/inexio/thola/core/request"
"github.com/spf13/cobra"
)

func init() {
addDeviceFlags(checkServerCMD)
checkCMD.AddCommand(checkServerCMD)
}

var checkServerCMD = &cobra.Command{
Use: "server",
Short: "Check the server specific metrics of a device",
Long: "Checks the server specific metrics of a device.\n\n" +
"The usage will be printed as performance data.",
Run: func(cmd *cobra.Command, args []string) {
r := request.CheckServerRequest{
CheckDeviceRequest: getCheckDeviceRequest(args[0]),
}
handleRequest(&r)
},
}
9 changes: 0 additions & 9 deletions cmd/device_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ func addDeviceFlags(cmd *cobra.Command) {
}

func bindDeviceFlags(cmd *cobra.Command) error {
if x := cmd.Flags().Lookup("ip"); x != nil {
err := viper.BindPFlag("device.ip", x)
if err != nil {
log.Error().
AnErr("Error", err).
Msg("Can't bind flag ip")
return err
}
}
if x := cmd.Flags().Lookup("timeout"); x != nil {
err := viper.BindPFlag("request.timeout", x)
if err != nil {
Expand Down
23 changes: 23 additions & 0 deletions cmd/read_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cmd

import (
"github.com/inexio/thola/core/request"
"github.com/spf13/cobra"
)

func init() {
addDeviceFlags(readServerCMD)
readCMD.AddCommand(readServerCMD)
}

var readServerCMD = &cobra.Command{
Use: "server",
Short: "Read out server specific information of a device",
Long: "Read out server specific information of a device like disk usage or process count.",
Run: func(cmd *cobra.Command, args []string) {
request := request.ReadServerRequest{
ReadRequest: getReadRequest(args[0]),
}
handleRequest(&request)
},
}
13 changes: 12 additions & 1 deletion config/device-classes/generic/arista_eos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,15 @@ match:
- "Arista Networks EOS"

identify:
properties:
properties:
vendor:
- detection: constant
value: "Arista Networks"
os_version:
- detection: SysDescription
oid: "1.3.6.1.2.1.1.1.0"
operators:
- type: modify
modify_method: regexSubmatch
regex: 'Arista Networks EOS version ([^\s]+)'
format: "$1"
22 changes: 22 additions & 0 deletions config/device-classes/generic/extremeos.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: "extremeos"

match:
logical_operator: "OR"
conditions:
- type: SysObjectID
match_mode: startsWith
values:
- .1.3.6.1.4.1.1916.2.291

identify:
properties:
vendor:
- detection: constant
value: "Extreme Networks"
os_version:
- detection: SysDescription
operators:
- type: modify
modify_method: regexSubmatch
regex: 'ExtremeXOS \(EXOS-VM\) version ([^\s]+)'
format: "$1"
13 changes: 12 additions & 1 deletion config/device-classes/generic/linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ config:
components:
cpu: true
memory: true
server: true

match:
logical_operator: OR
Expand Down Expand Up @@ -37,4 +38,14 @@ components:
modify_method: divide
value:
detection: constant
value: 100
value: 100
server:
procs:
- detection: snmpget
oid: ".1.3.6.1.2.1.25.1.6.0"
disk:
- detection: snmpget
value: ".1.3.6.1.4.1.2021.6.9.0"
users:
- detection: snmpget
oid: "1.3.6.1.2.1.25.1.5.0"
30 changes: 30 additions & 0 deletions config/device-classes/generic/pfsense.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: "pfsense"

match:
logical_operator: "OR"
conditions:
- type: SysObjectID
match_mode: startsWith
values:
- .1.3.6.1.4.1.12325

identify:
properties:
vendor:
- detection: constant
value: "Pfsense"
os_version:
- detection: snmpget
oid: "1.3.6.1.2.1.25.6.3.1.2.1"
operators:
- type: modify
modify_method: regexSubmatch
regex: 'FreeBSD: FreeBSD ([^\s]+)'
format: "$1"
model:
- detection: SysDescription
operators:
- type: modify
modify_method: regexSubmatch
regex: '([^\s]+) pfSense.localdomain ([^\s]+)'
format: "$1 $2"
22 changes: 22 additions & 0 deletions config/device-classes/generic/vyos.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: "vyos"

match:
logical_operator: "OR"
conditions:
- type: SysObjectID
match_mode: startsWith
values:
- .1.3.6.1.4.1.30803

identify:
properties:
vendor:
- detection: constant
value: "Vyatta"
os_version:
- detection: SysDescription
operators:
- type: modify
modify_method: regexSubmatch
regex: 'Vyatta VyOS ([^\s]+)'
format: "$1"
12 changes: 12 additions & 0 deletions core/communicator/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ func (c *baseCommunicator) GetMemoryComponentMemoryUsage(_ context.Context) (flo
return 0, tholaerr.NewNotImplementedError("function is not implemented for this communicator")
}

func (c *baseCommunicator) GetServerComponentDisk(_ context.Context) (int, error) {
return 0, tholaerr.NewNotImplementedError("function is not implemented for this communicator")
}

func (c *baseCommunicator) GetServerComponentProcs(_ context.Context) (int, error) {
return 0, tholaerr.NewNotImplementedError("function is not implemented for this communicator")
}

func (c *baseCommunicator) GetServerComponentUsers(_ context.Context) (int, error) {
return 0, tholaerr.NewNotImplementedError("function is not implemented for this communicator")
}

func (c *baseCommunicator) GetUPSComponentAlarmLowVoltageDisconnect(_ context.Context) (int, error) {
return 0, tholaerr.NewNotImplementedError("function is not implemented for this communicator")
}
Expand Down
Loading

0 comments on commit ab00db2

Please sign in to comment.