Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit e50ff92

Browse files
authored
Merge branch 'master' into token-caching
2 parents 466a99a + b4bc342 commit e50ff92

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

examples/logging_write.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
"""Logging Service example using write."""
5+
6+
import os
7+
import sys
8+
9+
curpath = os.path.dirname(os.path.abspath(__file__))
10+
sys.path[:0] = [os.path.join(curpath, os.pardir)]
11+
12+
from pancloud import LoggingService
13+
from pancloud import Credentials
14+
15+
16+
VENDOR_ID = 'panw'
17+
LOG_TYPE = 'threat'
18+
19+
url = 'https://apigw-stg4.us.paloaltonetworks.com'
20+
21+
c = Credentials()
22+
23+
# Create Logging Service instance
24+
ls = LoggingService(
25+
url=url,
26+
credentials=c
27+
)
28+
29+
data = [
30+
{
31+
'generatedTime': 0,
32+
'uuid': 1,
33+
'user': 'acme/wcoyote',
34+
'action': 'drop',
35+
'type': 'vulnerability',
36+
'subType': 'brute-force',
37+
'name': 'anvil',
38+
'repeatCnt': 5
39+
}
40+
]
41+
42+
q = ls.write(vendor_id=VENDOR_ID, log_type=LOG_TYPE, data=data)
43+
44+
print(
45+
"\nWRITE: {}\n".format(q.text)
46+
)

pancloud/httpclient.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def request(self, **kwargs):
235235
'timeout']:
236236
if x in kwargs and x == 'data':
237237
d = kwargs.pop(x)
238-
if type(d) is dict:
238+
if type(d) is dict or type(d) is list:
239239
k[x] = json.dumps(d) # convert to str
240240
else: # let requests handle the form-encoding
241241
k[x] = d

pancloud/logging.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,37 @@ def _delete(query_id, **kwargs):
300300
for x in self.xpoll(query_id, sequence_no, params, delete_query,
301301
**kwargs):
302302
yield x
303+
304+
def write(self, vendor_id=None, log_type=None, data=None, **kwargs):
305+
"""Write log records to the Logging Service.
306+
307+
This API requires a JSON array in its request body, each element
308+
of which represents a single log record. Log records are
309+
provided as JSON objects. Every log record must include the
310+
primary timestamp field that you identified when you registered
311+
your app. Every log record must also identify the log type.
312+
313+
Args:
314+
vendor_id (str): Vendor ID.
315+
log_type (str): Log type.
316+
data (dict): Payload/request dictionary.
317+
**kwargs: Supported :meth:`~pancloud.httpclient.HTTPClient.request` parameters.
318+
319+
Returns:
320+
requests.Response: Requests Response() object.
321+
322+
Examples:
323+
Refer to ``logging_write.py`` example.
324+
325+
"""
326+
path = "/logging-service/v1/logs/{}/{}".format(
327+
vendor_id, log_type
328+
)
329+
r = self._httpclient.request(
330+
method="POST",
331+
url=self.url,
332+
data=data,
333+
path=path,
334+
**kwargs
335+
)
336+
return r

0 commit comments

Comments
 (0)