How to dismiss a Lametric Nofitication using power

2019-08-25 10:42发布

This is a followup question to this comment about dismissing a notification on the Lametric clock. We use the Lametric clock to display notifications whenever a build fails. So far, someone would need to get up and physically press the button on the Lametric clock to dismiss the notification again. How can this be solved using powershell?

1条回答
混吃等死
2楼-- · 2019-08-25 11:03

To solve this, we first made a GET request to get a list of notifications IDs in the queue of the Lametric clock:

$request = @{uri = 'http://192.168.37.75:8080/api/v2';
            Method = 'GET';
            Headers = @{Authorization = 'Basic <base64-encoded-authentication-string>'; "Content-Type" = 'application/json' }
  }

$notifications = invoke-webrequest -UseBasicParsing @request


$request = @{uri = 'http://192.168.37.75:8080/api/v2/device/notifications';
            Method = 'GET';
            Headers = @{Authorization = 'Basic <base64-encoded-authentication-string>'; "Content-Type" = 'application/json' }
  }

$notifications = invoke-webrequest -UseBasicParsing @request

This will return an object with a property content containing a JSON string. This can be converted to a list of objects:

$notification = $notifications.Content | ConvertFrom-Json

Taking the first element from that list we can generate the URI to call

$notificationUri = 'http://192.168.37.75:8080/api/v2/device/notifications/' + $notification[0].ID;

and use that to dismiss the notification

$request = @{uri = $notificationUri
            Method = 'DELETE';
            Headers = @{Authorization = 'Basic <base64-encoded-authentication-string>'; "Content-Type" = 'application/json' }
  }

invoke-webrequest -UseBasicParsing @request
查看更多
登录 后发表回答