Skip to content

Conversation

@junaid1460
Copy link

@junaid1460 junaid1460 commented Aug 2, 2020

Description

Fixes mattermost 400 bad request due to data type mismatch caused by schema mismatch and adds missing text field to payload.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Test Configuration:

  • Hardware: Macbook Pro 16

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code

ref: alerts.py / MattermostAlerter.populate_fields
explicitly mentions field strcture with fallbacks
@junaid1460 junaid1460 force-pushed the fix/mattermost-400-badrequest branch from bbe2040 to a502de8 Compare August 2, 2020 17:25
@junaid1460
Copy link
Author

@Qmando @danielpops

@junaid1460
Copy link
Author

junaid1460 commented Aug 3, 2020

alert:
- "mattermost"
mattermost_webhook_url: "https://...."

mattermost_username_override: ....
mattermost_icon_url_override: ....
mattermost_msg_fields:
- title: Stack
  value: "{0} {1}" # interpolate fields mentioned in args
  short: false
  args: ["type", "msg.status_code"] # fields from doc
- title: Name
  value: static field
  short: false

This example must be added to doc

@junaid1460 junaid1460 force-pushed the fix/mattermost-400-badrequest branch from e14bbb8 to 378d471 Compare August 3, 2020 07:02
@sachincool
Copy link

sachincool commented Aug 3, 2020

Can confirm, this PR worked for me! Thanks @junaid1460 👍 🔥 Great work 🚀 LGTM

@nsano-rururu
Copy link
Contributor

@junaid1460

Have you checked the operation after changing the code?

    [{'title': 'Name', 'value': 'static field', 'short': False}] is not of type 'object'
    
    Failed validating 'type' in schema['properties']['mattermost_msg_fields']:
        {'additionalProperties': False,
         'properties': {'args': {'items': {'type': 'string'},
                                 'type': ['string', 'array']},
                        'short': {'type': 'boolean'},
                        'title': {'type': 'string'},
                        'value': {'type': 'string'}},
         'type': 'object'}
    
    On instance['mattermost_msg_fields']:
        [{'short': False, 'title': 'Name', 'value': 'static field'}]

@junaid1460
Copy link
Author

junaid1460 commented Jun 6, 2021

@junaid1460

Have you checked the operation after changing the code?

    [{'title': 'Name', 'value': 'static field', 'short': False}] is not of type 'object'
    
    Failed validating 'type' in schema['properties']['mattermost_msg_fields']:
        {'additionalProperties': False,
         'properties': {'args': {'items': {'type': 'string'},
                                 'type': ['string', 'array']},
                        'short': {'type': 'boolean'},
                        'title': {'type': 'string'},
                        'value': {'type': 'string'}},
         'type': 'object'}
    
    On instance['mattermost_msg_fields']:
        [{'short': False, 'title': 'Name', 'value': 'static field'}]

I have not updated this to work with latest versions, as of now closing this PR

@junaid1460 junaid1460 closed this Jun 6, 2021
@nsano-rururu
Copy link
Contributor

@junaid1460

I got an error even before your change. If you delete the following mattermost_msg_fields from schema.yaml, there seems to be no problem.

  mattermostField: &mattermostField
    type: object
    additionalProperties: false
    properties:
      title: {type: string}
      value: {type: string}
      args: *arrayOfString
      short: {type: boolean}
mattermost_msg_fields: *mattermostField

@nsano-rururu
Copy link
Contributor

It seems to be a bug since the alert notification to mattermost was added. Perhaps neither the person who made the pull request nor the person who reviewed and merged it was confirmed to work.

@nsano-rururu
Copy link
Contributor

It seems that there is no problem if you modify schema.yaml as follows.

  mattermostField: &mattermostField
    type: object
    additionalProperties: false
    properties:
      title: {type: string}
      value: {type: string}
      args: *arrayOfString
      short: {type: boolean}

  arrayOfMattermostFields: &arrayOfMattermostField
    type: array
    items: *mattermostField
  mattermost_msg_fields: *arrayOfMattermostField

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants