martindstone / pagerduty-cli

A command line interface for PagerDuty
MIT License
91 stars 13 forks source link

Services:set Intelligent Alert Grouping and Auto Pause #29

Closed wtsidney2016 closed 2 years ago

wtsidney2016 commented 2 years ago

Unable to enable Intelligent Alert Grouping using pd services:set

 % pd service:set -i=PXPW401 -k=alert_grouping_parameters -v="{ type: 'intelligent', config: {} }"        
 ›   Warning: pagerduty-cli update available from 0.1.0 to 0.1.3.

500 Internal Server Error
Setting alert_grouping_parameters = '{ type: 'intelligent', config: {} }' on 1 services 0/1 👍, 1/1 👎... done
Failed to set service PXPW401: 500 Internal Server Error
wtsidney2016 commented 2 years ago

Would also like to be able to set auto_pause_notifications_parameters from pd service:set

    "auto_pause_notifications_parameters": {
      "enabled": true,
      "timeout": 300
    }
wtsidney2016 commented 2 years ago

Also tried to enable setting alert_grouping_parameters.type

%  pd service:set -i=PXPW401 -k=alert_grouping_parameters.type -v='intelligent' 
 ›   Warning: pagerduty-cli update available from 0.1.0 to 0.1.3.

Setting alert_grouping_parameters.type = 'intelligent' on 1 services 1/1 👍, 0/1 👎... done
Failed to set value on service PXPW401
sdenef-adeo commented 2 years ago

Hello,

Same issue here

$> pd version 
pagerduty-cli/0.1.4 darwin-arm64 node-v16.15.0

AFAIU it seems to be due to the data submitted towards the API. I can't find the right CLI syntax to have a JSON object, it's a string.

  data: {
    service: {
      id: 'Pxxxxxx',
      type: 'service_reference',
      'alert_grouping_parameters.type': 'intelligent'
    }

or

  data: {
    service: {
      id: 'Pxxxxxx',
      type: 'service_reference',
      alert_grouping_parameters: '{"type": "intelligent"}'
    }
  }

A workaround is to use the deprecated alert_grouping parameter.

$> echo "Enable alert grouping" ; pd service:set -i Pxxxx -k alert_grouping -v "intelligent"
$> echo "Disable alert grouping" ; pd service:set -i Pxxxx -k alert_grouping -v ""

Regards

martindstone commented 2 years ago

Sorry everyone, yes, as you have noticed, key paths and/or direct JSON is not supported by the *:set commands... the best current workaround is to use rest put instead, like this:

pd rest put -e services/MY_SERVICE_ID -d '{"service": {"auto_pause_notifications_parameters": {"enabled": true, "timeout": 300}}}'

I will start thinking on how to make the *:set commands better for this sort of thing... I am thinking about two possible approaches --

Ideally I would do both

wtsidney2016 commented 2 years ago

Extending the :set command to accept json would be nice.

I was able to use use pd CLI to enable auto_pause - Thank You!

martindstone commented 2 years ago

Hi, I added the ability to give JSON as the value; you can also give JSON dot path notation as the key; also you can give -k and -v multiple times (in order) to set multiple key/values at once. Example screenshot:

image

This is in v0.1.5, now released as an RC, pd update rc to try it, pd update stable if you want to switch back to 0.1.4... can you give it a try and let me know if it's resolved for you? Thanks

sdenef-adeo commented 2 years ago

JSON dot path notation works fine for me. Tested:

$> pd version  
pagerduty-cli/0.1.5 darwin-arm64 node-v16.15.0
martindstone commented 2 years ago

Thank you @sdenef-adeo! I will be looking to close this issue and promote this build to stable soon.

martindstone commented 2 years ago

Hi, I just promoted this build to stable so closing this issue...