Skip to content

Commit 1764c84

Browse files
author
Shiyue Cheng
committed
Includes new endpoints for February release (0.8)
1 parent e29586f commit 1764c84

10 files changed

Lines changed: 207 additions & 255 deletions

examples/org_wide_clients.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,25 @@
44

55
import meraki
66

7-
# Either input your API key below by uncommenting line 10 and changing line 15 to api_key=api_key,
7+
# Either input your API key below by uncommenting line 10 and changing line 16 to api_key=api_key,
88
# or set an environment variable (preferred) to define your API key. The former is insecure and not recommended.
99
# For example, in Linux/macOS: export MERAKI_DASHBOARD_API_KEY=093b24e85df15a3e66f1fc359f4c48493eaa1b73
1010
# api_key = '093b24e85df15a3e66f1fc359f4c48493eaa1b73'
1111

1212

1313
def main():
1414
# Instantiate a Meraki dashboard API session
15-
dashboard = meraki.DashboardAPI(api_key=None, base_url='https://api.meraki.com/api/v0/', log_file_prefix=__file__[:-3], print_console=False)
15+
dashboard = meraki.DashboardAPI(
16+
api_key='',
17+
base_url='https://api-mp.meraki.com/api/v0/',
18+
log_file_prefix=os.path.basename(__file__)[:-3],
19+
log_path='',
20+
print_console=False
21+
)
1622

1723
# Get list of organizations to which API key has access
1824
organizations = dashboard.organizations.getOrganizations()
19-
25+
2026
# Iterate through list of orgs
2127
for org in organizations:
2228
print(f'\nAnalyzing organization {org["name"]}:')

meraki/__init__.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
from .api.malware_settings import MalwareSettings
5050
from .api.management_interface_settings import ManagementInterfaceSettings
5151
from .api.meraki_auth_users import MerakiAuthUsers
52+
from .api.monitored_media_servers import MonitoredMediaServers
5253
from .api.named_tag_scope import NamedTagScope
5354
from .api.netflow_settings import NetFlowSettings
5455
from .api.networks import Networks
@@ -79,7 +80,7 @@
7980
from .api.wireless_settings import WirelessSettings
8081
from .config import (
8182
API_KEY_ENVIRONMENT_VARIABLE, DEFAULT_BASE_URL, SINGLE_REQUEST_TIMEOUT, CERTIFICATE_PATH, WAIT_ON_RATE_LIMIT,
82-
MAXIMUM_RETRIES, OUTPUT_LOG, LOG_FILE_PREFIX, PRINT_TO_CONSOLE, SIMULATE_API_CALLS
83+
MAXIMUM_RETRIES, OUTPUT_LOG, LOG_PATH, LOG_FILE_PREFIX, PRINT_TO_CONSOLE, SIMULATE_API_CALLS
8384
)
8485

8586

@@ -94,23 +95,26 @@ class DashboardAPI(object):
9495
- wait_on_rate_limit (boolean): retry if 429 rate limit error encountered?
9596
- maximum_retries_on_rate_limit (integer): retry up to this many times when encountering 429s or other server-side errors
9697
- output_log (boolean): create an output log file?
98+
- log_path (string): path to output log; by default, working directory of script if not specified
9799
- log_file_prefix (string): log file name appended with date and timestamp
98100
- print_console (boolean): if output log used, output to console too?
99101
- simulate (boolean): simulate POST/PUT/DELETE calls to prevent changes?
100102
"""
101103

102104
def __init__(self, api_key=None, base_url=DEFAULT_BASE_URL, single_request_timeout=SINGLE_REQUEST_TIMEOUT,
103105
certificate_path=CERTIFICATE_PATH, wait_on_rate_limit=WAIT_ON_RATE_LIMIT,
104-
maximum_retries=MAXIMUM_RETRIES, output_log=OUTPUT_LOG, log_file_prefix=LOG_FILE_PREFIX,
105-
print_console=PRINT_TO_CONSOLE, simulate=SIMULATE_API_CALLS):
106+
maximum_retries=MAXIMUM_RETRIES, output_log=OUTPUT_LOG, log_path=LOG_PATH,
107+
log_file_prefix=LOG_FILE_PREFIX, print_console=PRINT_TO_CONSOLE, simulate=SIMULATE_API_CALLS):
106108
# Check API key
107109
api_key = api_key or os.environ.get(API_KEY_ENVIRONMENT_VARIABLE)
108110
if not api_key:
109111
raise APIKeyError()
110112

111113
# Configure logging
112114
self._logger = logging.getLogger(__name__)
113-
self._log_file = f'{log_file_prefix}_log__{datetime.now():%Y-%m-%d_%H-%M-%S}.log'
115+
if log_path and log_path[-1] != '/':
116+
log_path += '/'
117+
self._log_file = f'{log_path}{log_file_prefix}_log__{datetime.now():%Y-%m-%d_%H-%M-%S}.log'
114118
if output_log:
115119
logging.basicConfig(
116120
filename=self._log_file,
@@ -183,6 +187,7 @@ def __init__(self, api_key=None, base_url=DEFAULT_BASE_URL, single_request_timeo
183187
self.malware_settings = MalwareSettings(self._session)
184188
self.management_interface_settings = ManagementInterfaceSettings(self._session)
185189
self.meraki_auth_users = MerakiAuthUsers(self._session)
190+
self.monitored_media_servers = MonitoredMediaServers(self._session)
186191
self.named_tag_scope = NamedTagScope(self._session)
187192
self.netflow_settings = NetFlowSettings(self._session)
188193
self.networks = Networks(self._session)

meraki/api/clients.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,24 @@ def getNetworkClients(self, networkId: str, total_pages=1, direction='next', **k
5555
return self._session.get_pages(metadata, resource, params, total_pages, direction)
5656

5757

58-
def provisionNetworkClients(self, networkId: str, **kwargs):
58+
def provisionNetworkClients(self, networkId: str, mac: str, devicePolicy: str, **kwargs):
5959
"""
6060
**Provisions a client with a name and policy. Clients can be provisioned before they associate to the network.**
6161
https://api.meraki.com/api_docs#provisions-a-client-with-a-name-and-policy
6262
6363
- networkId (string)
6464
- mac (string): The MAC address of the client. Required.
65-
- name (string): The display name for the client. Optional. Limited to 255 bytes.
6665
- devicePolicy (string): The policy to apply to the specified client. Can be 'Whitelisted', 'Blocked', 'Normal' or 'Group policy'. Required.
67-
- groupPolicyId (string): The ID of the desired group policy to apply to the client. Required if 'devicePolicy' is set to "Group policy". Otherwise this is ignored.
66+
- name (string): The display name for the client. Optional. Limited to 255 bytes.
67+
- groupPolicyId (integer): The ID of the desired group policy to apply to the client. Required if 'devicePolicy' is set to "Group policy". Otherwise this is ignored.
6868
"""
6969

7070
kwargs.update(locals())
7171

72+
if 'devicePolicy' in kwargs:
73+
options = ['Whitelisted', 'Blocked', 'Normal', 'Group policy']
74+
assert kwargs['devicePolicy'] in options, f'''"devicePolicy" cannot be "{kwargs['devicePolicy']}", & must be set to one of: {options}'''
75+
7276
metadata = {
7377
'tags': ['Clients'],
7478
'operation': 'provisionNetworkClients',
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
class MonitoredMediaServers(object):
2+
def __init__(self, session):
3+
super(MonitoredMediaServers, self).__init__()
4+
self._session = session
5+
6+
def getOrganizationInsightMonitoredMediaServers(self, organizationId: str):
7+
"""
8+
**List the monitored media servers for this organization. Only valid for organizations with Meraki Insight.**
9+
https://api.meraki.com/api_docs#list-the-monitored-media-servers-for-this-organization
10+
11+
- organizationId (string)
12+
"""
13+
14+
metadata = {
15+
'tags': ['Monitored media servers'],
16+
'operation': 'getOrganizationInsightMonitoredMediaServers',
17+
}
18+
resource = f'/organizations/{organizationId}/insight/monitoredMediaServers'
19+
20+
return self._session.get(metadata, resource)
21+
22+
def createOrganizationInsightMonitoredMediaServer(self, organizationId: str, name: str, address: str):
23+
"""
24+
**Add a media server to be monitored for this organization. Only valid for organizations with Meraki Insight.**
25+
https://api.meraki.com/api_docs#add-a-media-server-to-be-monitored-for-this-organization
26+
27+
- organizationId (string)
28+
- name (string): The name of the VoIP provider
29+
- address (string): The IP address (IPv4 only) or hostname of the media server to monitor
30+
"""
31+
32+
kwargs = locals()
33+
34+
metadata = {
35+
'tags': ['Monitored media servers'],
36+
'operation': 'createOrganizationInsightMonitoredMediaServer',
37+
}
38+
resource = f'/organizations/{organizationId}/insight/monitoredMediaServers'
39+
40+
body_params = ['name', 'address']
41+
payload = {k: v for (k, v) in kwargs.items() if k in body_params}
42+
43+
return self._session.post(metadata, resource, payload)
44+
45+
def getOrganizationInsightMonitoredMediaServer(self, organizationId: str, monitoredMediaServerId: str):
46+
"""
47+
**Return a monitored media server for this organization. Only valid for organizations with Meraki Insight.**
48+
https://api.meraki.com/api_docs#return-a-monitored-media-server-for-this-organization
49+
50+
- organizationId (string)
51+
- monitoredMediaServerId (string)
52+
"""
53+
54+
metadata = {
55+
'tags': ['Monitored media servers'],
56+
'operation': 'getOrganizationInsightMonitoredMediaServer',
57+
}
58+
resource = f'/organizations/{organizationId}/insight/monitoredMediaServers/{monitoredMediaServerId}'
59+
60+
return self._session.get(metadata, resource)
61+
62+
def updateOrganizationInsightMonitoredMediaServer(self, organizationId: str, monitoredMediaServerId: str, **kwargs):
63+
"""
64+
**Update a monitored media server for this organization. Only valid for organizations with Meraki Insight.**
65+
https://api.meraki.com/api_docs#update-a-monitored-media-server-for-this-organization
66+
67+
- organizationId (string)
68+
- monitoredMediaServerId (string)
69+
- name (string): The name of the VoIP provider
70+
- address (string): The IP address (IPv4 only) or hostname of the media server to monitor
71+
"""
72+
73+
kwargs.update(locals())
74+
75+
metadata = {
76+
'tags': ['Monitored media servers'],
77+
'operation': 'updateOrganizationInsightMonitoredMediaServer',
78+
}
79+
resource = f'/organizations/{organizationId}/insight/monitoredMediaServers/{monitoredMediaServerId}'
80+
81+
body_params = ['name', 'address']
82+
payload = {k: v for (k, v) in kwargs.items() if k in body_params}
83+
84+
return self._session.put(metadata, resource, payload)
85+
86+
def deleteOrganizationInsightMonitoredMediaServer(self, organizationId: str, monitoredMediaServerId: str):
87+
"""
88+
**Delete a monitored media server from this organization. Only valid for organizations with Meraki Insight.**
89+
https://api.meraki.com/api_docs#delete-a-monitored-media-server-from-this-organization
90+
91+
- organizationId (string)
92+
- monitoredMediaServerId (string)
93+
"""
94+
95+
metadata = {
96+
'tags': ['Monitored media servers'],
97+
'operation': 'deleteOrganizationInsightMonitoredMediaServer',
98+
}
99+
resource = f'/organizations/{organizationId}/insight/monitoredMediaServers/{monitoredMediaServerId}'
100+
101+
return self._session.delete(metadata, resource)
102+

meraki/api/mx_1_many_nat_rules.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def getNetworkOneToManyNatRules(self, networkId: str):
1919

2020
return self._session.get(metadata, resource)
2121

22-
def updateNetworkOneToManyNatRules(self, networkId: str, **kwargs):
22+
def updateNetworkOneToManyNatRules(self, networkId: str, rules: list):
2323
"""
2424
**Set the 1:Many NAT mapping rules for an MX network**
2525
https://api.meraki.com/api_docs#set-the-1many-nat-mapping-rules-for-an-mx-network
@@ -28,7 +28,7 @@ def updateNetworkOneToManyNatRules(self, networkId: str, **kwargs):
2828
- rules (array): An array of 1:Many nat rules
2929
"""
3030

31-
kwargs.update(locals())
31+
kwargs = locals()
3232

3333
metadata = {
3434
'tags': ['MX 1:Many NAT rules'],

0 commit comments

Comments
 (0)