How to dismiss a Lametric Nofitication using powershell

夙愿已清 提交于 2019-12-11 16:13: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:


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


来源:https://stackoverflow.com/questions/50643326/how-to-dismiss-a-lametric-nofitication-using-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!