-
Notifications
You must be signed in to change notification settings - Fork 24
/
pulsar.ext
executable file
·69 lines (52 loc) · 1.63 KB
/
pulsar.ext
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
import osquery
import json
import sys
import os
import traceback
import pulsar
from dotenv import load_dotenv
@osquery.register_plugin
class ConfigPlugin(osquery.ConfigPlugin):
"""Example config plugin"""
def name(self):
return "osquery_config"
def content(self):
return [
{
"source_one": json.dumps({
"schedule": {
"time_1": {
"query": "SELECT * FROM processes",
"interval": 1,
},
},
}),
}
]
@osquery.register_plugin
class LoggerPlugin(osquery.LoggerPlugin):
"""Example logger plugin"""
def __init__(self):
load_dotenv('/home/ubuntu/.env')
service_url = os.getenv('PULSAR_ENDPOINT')
topic = os.getenv('TOPIC')
token = os.getenv('DS_TOKEN')
self.client = pulsar.Client(service_url, authentication=pulsar.AuthenticationToken(token))
self.producer = self.client.create_producer(topic )
def name(self):
return "pulsar_logger"
def log_string(self, value):
try:
self.producer.send((value).encode('utf-8'))
return osquery.extensions.ttypes.ExtensionStatus(code=0, message="OK")
except:
print ("Unexpected error:", sys.exc_info()[0])
traceback.print_exc()
raise
def __del__(self):
self.client.close()
if __name__ == "__main__":
osquery.start_extension(
name="osquery_decodable",
version="1.0.0",)