Skip to content
This repository was archived by the owner on Jan 16, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/argus/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@



<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:400,700|Roboto&#43;Mono">
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Brandon%20Grotesque:400,700|Roboto&#43;Mono">
<style>
body, input {
font-family: 'Roboto', Helvetica, Arial, sans-serif;
font-family: 'Brandon Grotesque', Helvetica, Arial, sans-serif;
}
pre, code {
font-family: 'Roboto Mono', 'Courier New', 'Courier', monospace;
Expand Down
4 changes: 2 additions & 2 deletions docs/getting-started/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@



<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:400,700|Roboto&#43;Mono">
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Brandon%20Grotesque:400,700|Roboto&#43;Mono">
<style>
body, input {
font-family: 'Roboto', Helvetica, Arial, sans-serif;
font-family: 'Brandon Grotesque', Helvetica, Arial, sans-serif;
}
pre, code {
font-family: 'Roboto Mono', 'Courier New', 'Courier', monospace;
Expand Down
Binary file modified docs/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@



<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:400,700|Roboto&#43;Mono">
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Brandon%20Grotesque:400,700|Roboto&#43;Mono">
<style>
body, input {
font-family: 'Roboto', Helvetica, Arial, sans-serif;
font-family: 'Brandon Grotesque', Helvetica, Arial, sans-serif;
}
pre, code {
font-family: 'Roboto Mono', 'Courier New', 'Courier', monospace;
Expand Down
4 changes: 2 additions & 2 deletions docs/roadmap/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@



<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:400,700|Roboto&#43;Mono">
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Brandon%20Grotesque:400,700|Roboto&#43;Mono">
<style>
body, input {
font-family: 'Roboto', Helvetica, Arial, sans-serif;
font-family: 'Brandon Grotesque', Helvetica, Arial, sans-serif;
}
pre, code {
font-family: 'Roboto Mono', 'Courier New', 'Courier', monospace;
Expand Down
4 changes: 2 additions & 2 deletions docs/roadmap/v0.1.0/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@



<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:400,700|Roboto&#43;Mono">
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Brandon%20Grotesque:400,700|Roboto&#43;Mono">
<style>
body, input {
font-family: 'Roboto', Helvetica, Arial, sans-serif;
font-family: 'Brandon Grotesque', Helvetica, Arial, sans-serif;
}
pre, code {
font-family: 'Roboto Mono', 'Courier New', 'Courier', monospace;
Expand Down
2 changes: 1 addition & 1 deletion docs/source/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ publishDir = "../../docs"
accent = "deep-purple"

[params.font]
text = "Roboto"
text = "Brandon Grotesque"
code = "Roboto Mono"


Expand Down
Binary file modified docs/source/static/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 15 additions & 11 deletions pkg/argus.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"github.com/logicmonitor/k8s-argus/pkg/collector"
"github.com/logicmonitor/k8s-argus/pkg/config"
"github.com/logicmonitor/k8s-argus/pkg/constants"
"github.com/logicmonitor/k8s-argus/pkg/device"
"github.com/logicmonitor/k8s-argus/pkg/etcd"
"github.com/logicmonitor/k8s-argus/pkg/tree"
"github.com/logicmonitor/k8s-argus/pkg/types"
"github.com/logicmonitor/k8s-argus/pkg/watch"
"github.com/logicmonitor/k8s-argus/pkg/watch/namespace"
"github.com/logicmonitor/k8s-argus/pkg/watch/node"
"github.com/logicmonitor/k8s-argus/pkg/watch/pod"
Expand All @@ -25,7 +25,7 @@ import (
// Argus represents the Argus cli.
type Argus struct {
*types.Base
Watchers []watch.Watcher
Watchers []types.Watcher
}

func newLMClient(id, key, company string) *lm.DefaultApi {
Expand Down Expand Up @@ -67,6 +67,10 @@ func NewArgus(base *types.Base) (*Argus, error) {
Base: base,
}

deviceManager := &device.Manager{
Base: base,
}

deviceTree := &tree.DeviceTree{
Base: base,
}
Expand All @@ -82,26 +86,26 @@ func NewArgus(base *types.Base) (*Argus, error) {
}

etcdController := etcd.Controller{
Base: base,
DeviceManager: deviceManager,
}
_, err = etcdController.DiscoverByToken()
if err != nil {
return nil, err
}

argus.Watchers = []watch.Watcher{
namespace.Watcher{
argus.Watchers = []types.Watcher{
&namespace.Watcher{
Base: base,
DeviceGroups: deviceGroups,
},
node.Watcher{
Base: base,
&node.Watcher{
DeviceManager: deviceManager,
},
service.Watcher{
Base: base,
&service.Watcher{
DeviceManager: deviceManager,
},
pod.Watcher{
Base: base,
&pod.Watcher{
DeviceManager: deviceManager,
},
}

Expand Down
52 changes: 52 additions & 0 deletions pkg/device/builder/builder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package builder

import (
"github.com/logicmonitor/k8s-argus/pkg/types"
lm "github.com/logicmonitor/lm-sdk-go"
)

// Builder implements types.DeviceBuilder
type Builder struct {
types.DeviceBuilder
}

// Name implements types.DeviceBuilder.
func (b *Builder) Name(name string) types.DeviceOption {
return func(device *lm.RestDevice) {
device.Name = name
}
}

// DisplayName implements types.DeviceBuilder.
func (b *Builder) DisplayName(name string) types.DeviceOption {
return func(device *lm.RestDevice) {
device.DisplayName = name
}
}

// CollectorID implements types.DeviceBuilder.
func (b *Builder) CollectorID(id int32) types.DeviceOption {
return func(device *lm.RestDevice) {
device.PreferredCollectorId = id
}
}

// SystemCategories implements types.DeviceBuilder.
func (b *Builder) SystemCategories(categories string) types.DeviceOption {
return func(device *lm.RestDevice) {
device.CustomProperties = append(device.CustomProperties, lm.NameAndValue{
Name: "system.categories",
Value: categories,
})
}
}

// Auto implements types.DeviceBuilder.
func (b *Builder) Auto(name, value string) types.DeviceOption {
return func(device *lm.RestDevice) {
device.CustomProperties = append(device.CustomProperties, lm.NameAndValue{
Name: "auto." + name,
Value: value,
})
}
}
161 changes: 161 additions & 0 deletions pkg/device/device.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
package device

import (
"fmt"

"github.com/logicmonitor/k8s-argus/pkg/config"
"github.com/logicmonitor/k8s-argus/pkg/device/builder"
"github.com/logicmonitor/k8s-argus/pkg/types"

"github.com/logicmonitor/k8s-argus/pkg/utilities"
lm "github.com/logicmonitor/lm-sdk-go"
)

// Manager implements types.DeviceManager
type Manager struct {
*types.Base
*builder.Builder
}

func buildDevice(c *config.Config, options ...types.DeviceOption) *lm.RestDevice {
device := &lm.RestDevice{
CustomProperties: []lm.NameAndValue{
{
Name: "auto.clustername",
Value: c.ClusterName,
},
},
DisableAlerting: c.DisableAlerting,
HostGroupIds: "1",
PreferredCollectorId: c.PreferredCollector,
}

for _, option := range options {
option(device)
}

return device
}

// FindByName implements types.DeviceManager.
func (m *Manager) FindByName(name string) (*lm.RestDevice, error) {
return find("name", name, m.LMClient)
}

// FindByDisplayName implements types.DeviceManager.
func (m *Manager) FindByDisplayName(name string) (*lm.RestDevice, error) {
return find("displayName", name, m.LMClient)
}

// Add implements types.DeviceManager.
func (m *Manager) Add(options ...types.DeviceOption) (*lm.RestDevice, error) {
device := buildDevice(m.Config(), options...)
restResponse, apiResponse, err := m.LMClient.AddDevice(*device, false)
if _err := utilities.CheckAllErrors(restResponse, apiResponse, err); _err != nil {
return nil, err
}

return &restResponse.Data, nil
}

// UpdateAndReplaceByID implements types.DeviceManager.
func (m *Manager) UpdateAndReplaceByID(id int32, options ...types.DeviceOption) (*lm.RestDevice, error) {
device := buildDevice(m.Config(), options...)
restResponse, apiResponse, err := m.LMClient.UpdateDevice(*device, id, "replace")
if _err := utilities.CheckAllErrors(restResponse, apiResponse, err); _err != nil {
return nil, err
}

return &restResponse.Data, nil
}

// UpdateAndReplaceByName implements types.DeviceManager.
func (m *Manager) UpdateAndReplaceByName(name string, options ...types.DeviceOption) (*lm.RestDevice, error) {
d, err := m.FindByDisplayName(name)
if err != nil {
return nil, err
}

if d == nil {
return nil, nil
}

// Update the device.
device, err := m.UpdateAndReplaceByID(d.Id, options...)
if err != nil {
return nil, err
}

return device, nil
}

// UpdateAndReplaceFieldByID implements types.DeviceManager.
func (m *Manager) UpdateAndReplaceFieldByID(id int32, field string, options ...types.DeviceOption) (*lm.RestDevice, error) {
device := buildDevice(m.Config(), options...)
restResponse, apiResponse, err := m.LMClient.PatchDeviceById(*device, id, "replace", field)
if _err := utilities.CheckAllErrors(restResponse, apiResponse, err); _err != nil {
return nil, err
}

return &restResponse.Data, nil
}

// UpdateAndReplaceFieldByName implements types.DeviceManager.
func (m *Manager) UpdateAndReplaceFieldByName(name string, field string, options ...types.DeviceOption) (*lm.RestDevice, error) {
d, err := m.FindByDisplayName(name)
if err != nil {
return nil, err
}

if d == nil {
return nil, nil
}

// Update the device.
device, err := m.UpdateAndReplaceFieldByID(d.Id, field, options...)
if err != nil {
return nil, err
}

return device, nil
}

// DeleteByID implements types.DeviceManager.
func (m *Manager) DeleteByID(id int32) error {
restResponse, apiResponse, err := m.LMClient.DeleteDevice(id)
return utilities.CheckAllErrors(restResponse, apiResponse, err)
}

// DeleteByName implements types.DeviceManager.
func (m *Manager) DeleteByName(name string) error {
d, err := m.FindByDisplayName(name)
if err != nil {
return err
}

// TODO: Should this return an error?
if d == nil {
return nil
}

restResponse, apiResponse, err := m.LMClient.DeleteDevice(d.Id)
return utilities.CheckAllErrors(restResponse, apiResponse, err)
}

// Config implements types.DeviceManager.
func (m *Manager) Config() *config.Config {
return m.Base.Config
}

func find(field, name string, client *lm.DefaultApi) (*lm.RestDevice, error) {
filter := fmt.Sprintf("%s:%s", field, name)
restResponse, apiResponse, err := client.GetDeviceList("", -1, 0, filter)
if _err := utilities.CheckAllErrors(restResponse, apiResponse, err); _err != nil {
return nil, _err
}
if restResponse.Data.Total == 1 {
return &restResponse.Data.Items[0], nil
}

return nil, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,20 @@ func Find(parentID int32, name string, client *lm.DefaultApi) (*lm.RestDeviceGro
return deviceGroup, nil
}

// DeleteSubGroup deletes a subgroup from a device group with the specified
// name.
func DeleteSubGroup(deviceGroup *lm.RestDeviceGroup, name string, client *lm.DefaultApi) error {
for _, subGroup := range deviceGroup.SubGroups {
if subGroup.Name != name {
continue
}
restResponse, apiResponse, err := client.DeleteDeviceGroupById(subGroup.Id, true)
return utilities.CheckAllErrors(restResponse, apiResponse, err)
}

return nil
}

func create(name, appliesTo string, disableAlerting bool, parentID int32, client *lm.DefaultApi) (*lm.RestDeviceGroup, error) {
restResponse, apiResponse, err := client.AddDeviceGroup(lm.RestDeviceGroup{
Name: name,
Expand Down
Loading