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
Show all changes
33 commits
Select commit Hold shift + click to select a range
bb2c1f5
DEV-39965: Allow the user to specify a parent group during installation
Oct 12, 2018
5735cb4
Merge pull request #1 in DEV/k8s-argus from DEV-39965-allow-the-user-…
Oct 15, 2018
2d53e26
DEV-39965: Allow the user to specify a parent group during installation
Oct 16, 2018
3c03f96
Merge pull request #2 in DEV/k8s-argus from DEV-39965-allow-the-user-…
Oct 16, 2018
5dfab5b
DEV-40505: Sync the k8s resource to santaba when argus launches
Nov 1, 2018
4058f07
DEV-40434: The alert status of Pods and Services are disabled
Nov 2, 2018
e43a6a7
DEV-40505: Sync the k8s resource to santaba when argus launches
Nov 2, 2018
58a9125
Merge pull request #3 in DEV/k8s-argus from DEV-40505-sync-the-k8s-re…
Nov 6, 2018
33c0a67
Merge pull request #4 in DEV/k8s-argus from bugfix/DEV-40434-the-aler…
Nov 6, 2018
b4ce488
DEV-40505: Sync the k8s resource to santaba when argus launches
Nov 9, 2018
a03490e
Merge pull request #6 in DEV/k8s-argus from DEV-40505-sync-the-k8s-re…
Nov 10, 2018
e7c90f1
DEV-40779: Enable the alert on service group when it is created by argus
Nov 14, 2018
d36f943
Merge pull request #7 in DEV/k8s-argus from DEV-40779-enable-the-aler…
Nov 15, 2018
cc8efda
DEV-41432: Use IP as hostname for argus related devices
Dec 11, 2018
eb4fffb
DEV-41432: Use IP as hostname for argus related devices
Dec 13, 2018
16000b5
DEV-41459: Add a new device type for k8s devices
Dec 13, 2018
821500c
Merge pull request #9 in DEV/k8s-argus from DEV-41459-add-a-new-devic…
Dec 14, 2018
d570b4f
Merge pull request #8 in DEV/k8s-argus from DEV-41432-use-ip-as-hostn…
Dec 14, 2018
e6152f8
DEV-41432: Use IP as hostname for argus related devices
Dec 17, 2018
4079f66
Merge pull request #10 in DEV/k8s-argus from DEV-41432-use-ip-as-host…
Dec 17, 2018
f35228a
DEV-40217: Support to set log levels and improve logs in argus relate…
Dec 18, 2018
968a0ad
DEV-40217: Support to set log levels and improve logs in argus relate…
Dec 19, 2018
e56e41e
DEV-41682: Improve the argus code for the CI failure in GitHub
Dec 21, 2018
5a8c798
Merge pull request #12 in DEV/k8s-argus from DEV-41682-improve-the-ar…
Dec 26, 2018
f634986
Merge pull request #11 in DEV/k8s-argus from DEV-40217-support-to-set…
Dec 26, 2018
06bdd15
DEV-41947: Improve the initsync logic to prevent lost data after k8s …
Jan 9, 2019
c69d432
DEV-41947: Improve the initsync logic to prevent lost data after k8s …
Jan 10, 2019
fc8f4f7
Merge pull request #13 in DEV/k8s-argus from DEV-41947-improve-the-in…
Jan 11, 2019
f1a712e
DEV-42060: Don't create collector device for Kubernetes Clusters
Jan 14, 2019
54de896
Merge branch 'develop' into DEV-42060-don-t-create-collector-device-for
JeremyTangCD Jan 15, 2019
3fec7c2
Update pkg/device/device.go
woz5999 Jan 17, 2019
19a59c6
Update pkg/device/device.go
woz5999 Jan 17, 2019
979f578
Update device.go
JeremyTangCD Jan 17, 2019
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
2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


[[constraint]]
branch = "master"
branch = "v1"
name = "github.com/logicmonitor/lm-sdk-go"

[[constraint]]
Expand Down
66 changes: 59 additions & 7 deletions pkg/device/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,55 @@ func buildDevice(c *config.Config, client api.CollectorSetControllerClient, opti
return device
}

// checkAndUpdateExistingDevice tries to find and update the devices which needs to be changed
func (m *Manager) checkAndUpdateExistingDevice(device *lm.RestDevice) (*lm.RestDevice, error) {
oldDevice, err := m.FindByDisplayName(device.DisplayName)
if err != nil {
return nil, err
}
if oldDevice == nil {
return nil, fmt.Errorf("can not find the device: %s", device.DisplayName)
}

// the device which is not changed will be ignored
if device.Name == oldDevice.Name {
log.Infof("No changes to device (%s). Ignoring update", device.DisplayName)
return device, nil
}

// the device of the other cluster will be ignored
oldClusterName := ""
if oldDevice.CustomProperties != nil && len(oldDevice.CustomProperties) > 0 {
for _, cp := range oldDevice.CustomProperties {
if cp.Name == constants.K8sClusterNamePropertyKey {
oldClusterName = cp.Value
}
}
}
if oldClusterName != m.Config().ClusterName {
log.Infof("Device (%s) belongs to a different cluster (%s). Ignoring update", device.DisplayName, oldClusterName)
return device, nil
}

newDevice, err := m.updateAndReplace(oldDevice.Id, device)
if err != nil {
return nil, err
}
log.Infof("Finished updating the device: %s", newDevice.DisplayName)
return newDevice, nil
}

func (m *Manager) updateAndReplace(id int32, device *lm.RestDevice) (*lm.RestDevice, error) {

restResponse, apiResponse, err := m.LMClient.UpdateDevice(*device, id, "replace")
if _err := utilities.CheckAllErrors(restResponse, apiResponse, err); _err != nil {
return nil, _err
}
log.Debugf("%#v", restResponse)

return &restResponse.Data, nil
}

// FindByDisplayName implements types.DeviceManager.
func (m *Manager) FindByDisplayName(name string) (*lm.RestDevice, error) {
filter := fmt.Sprintf("displayName:%s", name)
Expand All @@ -71,6 +120,15 @@ func (m *Manager) Add(options ...types.DeviceOption) (*lm.RestDevice, error) {

restResponse, apiResponse, err := m.LMClient.AddDevice(*device, false)
if _err := utilities.CheckAllErrors(restResponse, apiResponse, err); _err != nil {
if restResponse != nil && restResponse.Status == 600 {
log.Infof("Check and Update the existing device: %s", device.DisplayName)
newDevice, err := m.checkAndUpdateExistingDevice(device)
if err != nil {
return nil, err
}
return newDevice, nil
}

return nil, _err
}
log.Debugf("%#v", restResponse)
Expand All @@ -83,13 +141,7 @@ func (m *Manager) UpdateAndReplaceByID(id int32, options ...types.DeviceOption)
device := buildDevice(m.Config(), m.ControllerClient, options...)
log.Debugf("%#v", device)

restResponse, apiResponse, err := m.LMClient.UpdateDevice(*device, id, "replace")
if _err := utilities.CheckAllErrors(restResponse, apiResponse, err); _err != nil {
return nil, _err
}
log.Debugf("%#v", restResponse)

return &restResponse.Data, nil
return m.updateAndReplace(id, device)
}

// UpdateAndReplaceByDisplayName implements types.DeviceManager.
Expand Down
4 changes: 2 additions & 2 deletions pkg/sync/initsyncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ func (i *InitSyncer) syncDevices(resourceType string, resourcesMap map[string]st
continue
}

name, exist := resourcesMap[device.DisplayName]
if !exist || name != device.Name {
_, exist := resourcesMap[device.DisplayName]
if !exist {
log.Infof("Delete the non-exist %v device: %v", resourceType, device.DisplayName)
err := i.DeviceManager.DeleteByID(device.Id)
if err != nil {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.