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

ansible-meraki module for Alert Settings #199

Closed
richardjohnallsopp opened this issue Sep 29, 2020 · 26 comments · Fixed by #204
Closed

ansible-meraki module for Alert Settings #199

richardjohnallsopp opened this issue Sep 29, 2020 · 26 comments · Fixed by #204
Assignees
Labels
new module Issue or pull request for a new module

Comments

@richardjohnallsopp
Copy link

I would love an ansible-meraki module to configure the alert settings for a network using this endpoint .

@kbreit kbreit self-assigned this Oct 4, 2020
@kbreit kbreit added the new module Issue or pull request for a new module label Oct 4, 2020
@kbreit
Copy link
Collaborator

kbreit commented Oct 6, 2020

Follow up on this one. I've spent some time on this last night and lunch today. Unfortunately, getting idempotency is more challenging than I thought. I'm working through it but taking longer than I hoped.

@kbreit
Copy link
Collaborator

kbreit commented Oct 8, 2020

@richardjohnallsopp I just submitted a pull request (#204) for this. Can you give it a try and let me know what you think? Thanks.

@richardjohnallsopp
Copy link
Author

richardjohnallsopp commented Oct 9, 2020 via email

@richardjohnallsopp
Copy link
Author

What is the process for getting these and running them? If you could point me to some docs I'd appreciate it.

@kbreit
Copy link
Collaborator

kbreit commented Oct 9, 2020

@richardjohnallsopp There are a couple of ways to go about this. The most straight forward and simple way is to download https://raw.githubusercontent.com/kbreit/ansible-meraki/module/meraki_alert/plugins/modules/meraki_alert.py and save it locally. You should have a directory called ~/.ansible/collections/ansible_collections/cisco/meraki. Copy that file into ~/.ansible/collections/ansible_collections/cisco/meraki/plugins/modules and you should be able to call it like any other module.

@richardjohnallsopp
Copy link
Author

Awesome, thanks man I'm off this weekend so will try all this out and report back.

@richardjohnallsopp
Copy link
Author

I get the following from this module:

(tanglewoodgames_meraki) flynn@NCL-WL-16612:~/tanglewoodgames_meraki$ ./configure_mx_home.sh --tags "configure_alerts"

PLAY [localhost] *****************************************************************************

TASK [Gathering Facts] ***********************************************************************
ok: [127.0.0.1]

TASK [configure alert settings] **************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'MerakiModule' object has no attribute 'convert_snake_to_camel'
fatal: [127.0.0.1 -> localhost]: FAILED! => changed=false 
  module_stderr: |-
    Traceback (most recent call last):
      File "/home/flynn/.ansible/tmp/ansible-tmp-1602436989.3608868-3174-24665290994372/AnsiballZ_meraki_alert.py", line 102, in <module>
        _ansiballz_main()
      File "/home/flynn/.ansible/tmp/ansible-tmp-1602436989.3608868-3174-24665290994372/AnsiballZ_meraki_alert.py", line 94, in _ansiballz_main
        invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
      File "/home/flynn/.ansible/tmp/ansible-tmp-1602436989.3608868-3174-24665290994372/AnsiballZ_meraki_alert.py", line 40, in invoke_module
        runpy.run_module(mod_name='ansible_collections.cisco.meraki.plugins.modules.meraki_alert', init_globals=None, run_name='__main__', alter_sys=True)
      File "/usr/lib/python3.6/runpy.py", line 205, in run_module
        return _run_module_code(code, init_globals, run_name, mod_spec)
      File "/usr/lib/python3.6/runpy.py", line 96, in _run_module_code
        mod_name, mod_spec, pkg_name, script_name)
      File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
        exec(code, run_globals)
      File "/tmp/ansible_meraki_alert_payload_x5wvf7o0/ansible_meraki_alert_payload.zip/ansible_collections/cisco/meraki/plugins/modules/meraki_alert.py", line 330, in <module>
      File "/tmp/ansible_meraki_alert_payload_x5wvf7o0/ansible_meraki_alert_payload.zip/ansible_collections/cisco/meraki/plugins/modules/meraki_alert.py", line 305, in main
      File "/tmp/ansible_meraki_alert_payload_x5wvf7o0/ansible_meraki_alert_payload.zip/ansible_collections/cisco/meraki/plugins/modules/meraki_alert.py", line 234, in construct_payload
    AttributeError: 'MerakiModule' object has no attribute 'convert_snake_to_camel'
  module_stdout: ''
  msg: |-
    MODULE FAILURE
    See stdout/stderr for the exact error
  rc: 1

@richardjohnallsopp
Copy link
Author

Let me know if I'm doing something wrong?

@kbreit
Copy link
Collaborator

kbreit commented Oct 12, 2020

I forgot about a change to the module utility I had to do. Please download https://raw.githubusercontent.com/CiscoDevNet/ansible-meraki/2c0bc3ba5d16de222d5c8d7a032a3b9fb4ef4ec9/plugins/module_utils/network/meraki/meraki.py and put it in the plugins/module_utils/network/meraki directory. That should fix it.

@richardjohnallsopp
Copy link
Author

Got it, will try and test today.

@kbreit
Copy link
Collaborator

kbreit commented Oct 14, 2020

@richardjohnallsopp Were you able to test this module?

@richardjohnallsopp
Copy link
Author

This one completes now, but do you have a list of names for the alert types? Also I have all_admins set to false and it keeps adding it back in. It does add the emails I've listed, but using the gatewayDown example doesn't set an alert.

@richardjohnallsopp
Copy link
Author

# configure alerts for network
    - name: configure alert settings
      meraki_alert:
        auth_key: "{{   auth_key  }}"
        org_name: "{{  org_name  }}"
        net_name: "{{  network_name  }}"
        state: present
        default_destinations:
          emails:
            "{{  email_list  }}"
          all_admins: false
          snmp: false
        alerts:
          - type: "gatewayDown"
            enabled: yes
            filters:
              timeout: 60
            alert_destinations:
              emails:
                "{{  email_list  }}"
              all_admins: false
              snmp: false
      delegate_to: localhost
      tags:
        - "configure_alerts"

@richardjohnallsopp
Copy link
Author

richardjohnallsopp commented Oct 16, 2020

I'm not sure how to translate these network alerts into alert type as I see no mention of gateway
image

@kbreit
Copy link
Collaborator

kbreit commented Oct 16, 2020

Hopefully I catch you while you're still working and able to test. Here is a list of alerts, which I'll add to the documentation and enforce. What type of network are you using? MX? If so, it's possible it changes the available alerts based on network type.

  • gatewayDown
  • gatewayToRepeater
  • repeaterDown
  • rogueAp
  • settingsChanged
  • vpnConnectivityChange
  • usageAlert
  • weeklyPresence

@richardjohnallsopp
Copy link
Author

Yeah it's an MX network, but it's not setting the alert type (maybe due to the type name) and it's adding all admins regardless of the bool setting.

@richardjohnallsopp
Copy link
Author

Yeah so that list you gave kinda makes sense on the MR network:
image
Do you know where to get the MX ones I listed above? It's annoying that API docs don't have a list of all alerts :-(

@kbreit
Copy link
Collaborator

kbreit commented Oct 16, 2020

I'm going to provide feedback to the API team to see if they can update documentation.

Regarding where to get it, I did a query (state: query) and it will list the full data structure for the entire network. There you'll manually pull the types.

@richardjohnallsopp
Copy link
Author

That worked to get the alert types and it works great, but it's still adding the all admins despite being set to false:
image

@kbreit
Copy link
Collaborator

kbreit commented Oct 16, 2020

I'm looking into the all admins problem right now.

@richardjohnallsopp
Copy link
Author

I'll post the alerts here for anyone else that might need them:

        type: ampMalwareDetected
        type: ampMalwareBlocked
        type: applianceDown
        type: failoverEvent
        type: dhcpNoLeases
        type: rogueDhcp
        type: ipConflict
        type: cellularUpDown
        type: clientConnectivity
        type: vrrp
        type: vpnConnectivityChange
        type: settingsChanged
        type: usageAlert

@kbreit
Copy link
Collaborator

kbreit commented Oct 16, 2020

Very helpful, thank you. I'm going to document these and probably enforce the values.

@kbreit
Copy link
Collaborator

kbreit commented Oct 16, 2020

@richardjohnallsopp I think I fixed the bug. It's pushed to the branch so please download the file and use the latest version. I've renamed type to alert_type as well.

@richardjohnallsopp
Copy link
Author

It's working great:
data

# list of alert type
alert_list:
  - type: "ampMalwareDetected"
    state: "yes"
  - type: "ampMalwareBlocked"
    state: "yes"
  - type: "applianceDown"
    state: "yes"
  - type: "failoverEvent"
    state: "yes"
  - type: "dhcpNoLeases"
    state: "no"
  - type: "rogueDhcp"
    state: "no"
  - type: "ipConflict"
    state: "no"
  - type: "cellularUpDown"
    state: "no"
  - type: "clientConnectivity"
    state: "no"
  - type: "vrrp"
    state: "no"
  - type: "vpnConnectivityChange"
    state: "no"
  - type: "settingsChanged"
    state: "no"
  - type: "usageAlert"
    state: "no"

task

   # configure alerts for network
    - name: configure alert settings
      meraki_alert:
        auth_key: "{{   auth_key  }}"
        org_name: "{{  org_name  }}"
        net_name: "{{  network_name  }}"
        state: present
        default_destinations:
          emails:
            "{{  email_list  }}"
          all_admins: false
          snmp: false
        alerts:
          - type: "{{  item.type  }}"
            enabled: "{{  item.state  }}"
            filters:
              timeout: 60
            alert_destinations:
              emails:
                "{{  email_list  }}"
              all_admins: false
              snmp: false
      delegate_to: localhost
      with_items: "{{  alert_list  }}"
      tags:
        - "configure_alert"

output
image

@richardjohnallsopp
Copy link
Author

Yup you fixed it, it all works perfectly, thanks so much for the hard work on this man!!

@kbreit
Copy link
Collaborator

kbreit commented Oct 16, 2020

@richardjohnallsopp 2.1.0 is released. Please redownload using ansible-galaxy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new module Issue or pull request for a new module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants