Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c7n mailer slack message to resource tag not working as expected #7154

Open
hopkinsnji opened this issue Mar 9, 2022 · 1 comment
Open
Labels

Comments

@hopkinsnji
Copy link

Describe the bug

I wrote a policy to send notifications to a channel pulled from a resource tag, there are several resources and all messages are being sent to one channel or not sent at all.

The notify action is set to send a slack message to a resource tag - slack://tag/resource_tag. When there are several resources, it only pulls the slack channel tag from one resource (last in the resource list), so if there is no channel tag on that resource, no message gets sent. If there are several resources with different channel tags, all the slack messages get sent to one channel.

On this line:
https://github.com/cloud-custodian/cloud-custodian/blob/master/tools/c7n_mailer/c7n_mailer/slack_delivery.py#L81
resource is not a variable that is explicitly set, but is seem to be the last iterable from a previous for loop
https://github.com/cloud-custodian/cloud-custodian/blob/master/tools/c7n_mailer/c7n_mailer/slack_delivery.py#L27-L31

What did you expect to happen?

I expected each slack channel that had a noncompliant resource to receive a message.

Cloud Provider

Amazon Web Services (AWS)

Cloud Custodian version and dependency information

c7n-mailer==0.6.13


Custodian:   0.9.14
Python:      3.9.5 (default, May 18 2021, 12:31:01) 
             [Clang 10.0.0 ]
Platform:    posix.uname_result(sysname='Darwin', nodename='MSP-C02G56SMMD', release='20.4.0', version='Darwin Kernel Version 20.4.0: Thu Apr 22 21:46:47 PDT 2021; root:xnu-7195.101.2~1/RELEASE_X86_64', machine='x86_64')
Using venv:  False
Docker: False
Installed: 

argcomplete==1.12.3
attrs==21.2.0
boto3==1.19.12
botocore==1.22.12
docutils==0.17.1
importlib-metadata==4.8.1
jmespath==0.10.0
jsonschema==3.2.0
pyrsistent==0.18.0
python-dateutil==2.8.2
pyyaml==5.4.1
s3transfer==0.5.0
setuptools==52.0.0.post20210125
six==1.12.0
tabulate==0.8.9
typing-extensions==3.10.0.2
urllib3==1.26.7
zipp==3.6.0

Policy

policies:
  - name: sg
    resource: security-group
    filters:
      - tag:cc: present
    actions:
      - type: notify
        slack_template: slack2
        violation_desc: test
        action_desc: test
        to: 
          - slack://tag/xxx:chat_room
        transport:
          type: sqs
          queue: https://sqs.us-east-1.amazonaws.com/1234/CCEmailerQueue

Relevant log/traceback output

No response

Extra information or context

No response

@mag-ve
Copy link

mag-ve commented Jul 12, 2023

Have there been any updates/workarounds to this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants