#  Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
---

- name: Get auth string
  shell: echo -n {{ powervault_me4_username }}_{{ powervault_me4_password }}  | sha256sum
  register: snmp_auth_string
  changed_when: false
  ignore_errors: yes
  tags: install

- name: Get session key
  uri:
    url: https://{{ inventory_hostname }}/api/login/{{ snmp_auth_string.stdout | replace(" -", "") }}
    method: GET
    headers:
      {'datatype': 'json'}
    validate_certs: no
  register: snmp_session_key
  tags: install

- name: Set snmp parameters
  uri:
    url: https://{{ inventory_hostname }}/api/set/snmp-parameters/enable/{{ powervault_me4_snmp_notify_level }}/add-trap-host/{{ snmp_trap_destination }}/read-community/{{ snmp_community_name }}
    method: GET
    body_format: json
    validate_certs: no
    use_proxy: no
    headers:
      {'sessionKey': "{{ snmp_session_key.json.status[0].response }}", 'datatype':'json'}
  register: snmp
  tags: install
