Skip to content

Commit

Permalink
Added read and check disk
Browse files Browse the repository at this point in the history
  • Loading branch information
toberd committed Mar 8, 2021
1 parent f16ef8f commit 32e4623
Show file tree
Hide file tree
Showing 18 changed files with 413 additions and 76 deletions.
82 changes: 80 additions & 2 deletions api/request_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func StartAPI() {

// swagger:operation POST /check/memory-usage check checkMemoryUsage
// ---
// summary: Read out the memory usage of a device.
// summary: Check the memory usage of a device.
// consumes:
// - application/json
// - application/xml
Expand All @@ -260,7 +260,7 @@ func StartAPI() {

// swagger:operation POST /check/cpu-load check checkCpuLoad
// ---
// summary: Read out the cpu load of a device.
// summary: Check the cpu load of a device.
// consumes:
// - application/json
// - application/xml
Expand Down Expand Up @@ -339,6 +339,33 @@ func StartAPI() {
// $ref: '#/definitions/OutputError'
e.POST("/check/server", checkServer)

// swagger:operation POST /check/disk check checkDisk
// ---
// summary: Check the disk 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/CheckDiskRequest'
// responses:
// 200:
// description: Returns the response.
// schema:
// $ref: '#/definitions/CheckDiskResponse'
// 400:
// description: Returns an error with more details in the body.
// schema:
// $ref: '#/definitions/OutputError'
e.POST("/check/disk", checkDisk)

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

// swagger:operation POST /read/disk read readDisk
// ---
// summary: Reads out disk 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/ReadDiskRequest'
// responses:
// 200:
// description: Returns the response.
// schema:
// $ref: '#/definitions/ReadDiskResponse'
// 400:
// description: Returns an error with more details in the body.
// schema:
// $ref: '#/definitions/OutputError'
e.POST("/read/disk", readDisk)

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

func checkDisk(ctx echo.Context) error {
r := request.CheckDiskRequest{}
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 @@ -861,6 +927,18 @@ func readServer(ctx echo.Context) error {
return returnInFormat(ctx, http.StatusOK, resp)
}

func readDisk(ctx echo.Context) error {
r := request.ReadDiskRequest{}
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_disk.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(checkDiskCMD)
checkCMD.AddCommand(checkDiskCMD)
}

var checkDiskCMD = &cobra.Command{
Use: "disk",
Short: "Check the disk of a device",
Long: "Checks the disk of a device.\n\n" +
"The metrics will be printed as performance data.",
Run: func(cmd *cobra.Command, args []string) {
r := request.CheckDiskRequest{
CheckDeviceRequest: getCheckDeviceRequest(args[0]),
}
handleRequest(&r)
},
}
23 changes: 23 additions & 0 deletions cmd/read_disk.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(readDiskCMD)
readCMD.AddCommand(readDiskCMD)
}

var readDiskCMD = &cobra.Command{
Use: "disk",
Short: "Read out storage information of a device",
Long: "Read out storage information of a device like types and used space of storages.",
Run: func(cmd *cobra.Command, args []string) {
request := request.ReadDiskRequest{
ReadRequest: getReadRequest(args[0]),
}
handleRequest(&request)
},
}
2 changes: 1 addition & 1 deletion cmd/read_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func init() {
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.",
Long: "Read out server specific information of a device like user or process count.",
Run: func(cmd *cobra.Command, args []string) {
request := request.ReadServerRequest{
ReadRequest: getReadRequest(args[0]),
Expand Down
26 changes: 23 additions & 3 deletions 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
disk: true
server: true

match:
Expand All @@ -23,6 +24,12 @@ components:
load:
- detection: snmpget
oid: ".1.3.6.1.4.1.2021.10.1.3.2"
operators:
- type: modify
modify_method: multiply
value:
detection: constant
value: 100
memory:
usage:
- detection: snmpget
Expand All @@ -39,13 +46,26 @@ components:
value:
detection: constant
value: 100
disk:
storages:
detection: snmpwalk
values:
type:
oid: ".1.3.6.1.2.1.25.2.3.1.2"
operators:
- type: modify
modify_method: map
mappings: hrStorageType.yaml
description:
oid: ".1.3.6.1.2.1.25.2.3.1.3"
available:
oid: ".1.3.6.1.2.1.25.2.3.1.5"
used:
oid: ".1.3.6.1.2.1.25.2.3.1.6"
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"
10 changes: 10 additions & 0 deletions config/mappings/hrStorageType.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.1.3.6.1.2.1.25.2.1.1: "Other"
.1.3.6.1.2.1.25.2.1.2: "RAM"
.1.3.6.1.2.1.25.2.1.3: "Virtual Memory"
.1.3.6.1.2.1.25.2.1.4: "Fixed Disk"
.1.3.6.1.2.1.25.2.1.5: "Removable Disk"
.1.3.6.1.2.1.25.2.1.6: "Floppy Disk"
.1.3.6.1.2.1.25.2.1.7: "Compact Disk"
.1.3.6.1.2.1.25.2.1.8: "RAM Disk"
.1.3.6.1.2.1.25.2.1.9: "Flash Memory"
.1.3.6.1.2.1.25.2.1.10: "Network Disk"
8 changes: 4 additions & 4 deletions core/communicator/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ 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")
}
Expand All @@ -71,6 +67,10 @@ func (c *baseCommunicator) GetServerComponentUsers(_ context.Context) (int, erro
return 0, tholaerr.NewNotImplementedError("function is not implemented for this communicator")
}

func (c *baseCommunicator) GetDiskComponentStorages(_ context.Context) ([]device.DiskComponentStorage, error) {
return nil, 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 32e4623

Please sign in to comment.