Debian Codegraph @

ansible_collections/cisco/intersight/plugins/modules/intersight_snmp_policy_info.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 from __future__ import absolute_import, division, print_function
7 __metaclass__ = type
8
9 ANSIBLE_METADATA = {'metadata_version': '1.1',
10 'status': ['preview'],
11 'supported_by': 'community'}
12
13 DOCUMENTATION = r'''
14 ---
15 module: intersight_snmp_policy_info
16 short_description: Gather information about SNMP Policies in Cisco Intersight
17 description:
18 - Gather information about SNMP Policies in L(Cisco Intersight,https://intersight.com).
19 - Information can be filtered by O(organization) and O(name).
20 - If no filters are passed, all SNMP Policies will be returned.
21 extends_documentation_fragment: intersight
22 options:
23 organization:
24 description:
25 - The name of the organization the SNMP Policy belongs to.
26 type: str
27 name:
28 description:
29 - The name of the SNMP Policy to gather information from.
30 type: str
31 author:
32 - Ron Gershburg (@rgershbu)
33 '''
34
35 EXAMPLES = r'''
36 - name: Fetch a specific SNMP Policy by name
37 cisco.intersight.intersight_snmp_policy_info:
38 api_private_key: "{{ api_private_key }}"
39 api_key_id: "{{ api_key_id }}"
40 name: "mixed-snmp-policy"
41
42 - name: Fetch all SNMP Policies in a specific Organization
43 cisco.intersight.intersight_snmp_policy_info:
44 api_private_key: "{{ api_private_key }}"
45 api_key_id: "{{ api_key_id }}"
46 organization: "default"
47
48 - name: Fetch all SNMP Policies
49 cisco.intersight.intersight_snmp_policy_info:
50 api_private_key: "{{ api_private_key }}"
51 api_key_id: "{{ api_key_id }}"
52 '''
53
54 RETURN = r'''
55 api_response:
56 description: The API response output returned by the specified resource.
57 returned: always
58 type: dict
59 sample:
60 "api_response": [
61 {
62 "Name": "mixed-snmp-policy",
63 "ObjectType": "snmp.Policy",
64 "Enabled": true,
65 "V2Enabled": true,
66 "V3Enabled": true,
67 "SnmpPort": 161,
68 "SysContact": "[email protected]",
69 "SysLocation": "Data Center A",
70 "CommunityAccess": "Full",
71 "AccessCommunityString": "public",
72 "TrapCommunity": "trapcomm",
73 "EngineId": "custom-engine-id",
74 "SnmpUsers": [
75 {
76 "Name": "admin",
77 "SecurityLevel": "AuthPriv",
78 "AuthType": "SHA",
79 "IsAuthPasswordSet": true,
80 "PrivacyType": "AES",
81 "IsPrivacyPasswordSet": true
82 }
83 ],
84 "SnmpTraps": [
85 {
86 "Enabled": true,
87 "Version": "V2",
88 "Community": "trapcomm",
89 "Type": "Trap",
90 "Destination": "192.168.1.100",
91 "Port": 162
92 }
93 ],
94 "Tags": [
95 {
96 "Key": "Environment",
97 "Value": "Production"
98 }
99 ]
100 },
101 {
102 "Name": "v3-only-snmp-policy",
103 "ObjectType": "snmp.Policy",
104 "Enabled": true,
105 "V3Enabled": true,
106 "SnmpPort": 161,
107 "SysContact": "[email protected]",
108 "SysLocation": "Data Center B",
109 "CommunityAccess": "Disabled",
110 "EngineId": "v3-engine-id",
111 "SnmpUsers": [
112 {
113 "Name": "v3user",
114 "SecurityLevel": "AuthPriv",
115 "AuthType": "SHA",
116 "IsAuthPasswordSet": true,
117 "PrivacyType": "AES",
118 "IsPrivacyPasswordSet": true
119 }
120 ],
121 "SnmpTraps": [],
122 "Tags": []
123 }
124 ]
125 '''
126
127
128 from ansible.module_utils.basic import AnsibleModule
129 from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec
130
131
132 def main():
133 argument_spec = intersight_argument_spec.copy()
134 argument_spec.update(
135 organization=dict(type='str'),
136 name=dict(type='str')
137 )
138 module = AnsibleModule(
139 argument_spec,
140 supports_check_mode=True,
141 )
142
143 intersight = IntersightModule(module)
144 intersight.result['api_response'] = {}
145 intersight.result['trace_id'] = ''
146
147 # Resource path used to fetch info
148 resource_path = '/snmp/Policies'
149
150 query_params = intersight.set_query_params()
151
152 intersight.get_resource(
153 resource_path=resource_path,
154 query_params=query_params,
155 return_list=True
156 )
157
158 module.exit_json(**intersight.result)
159
160
161 if __name__ == '__main__':
162 main()