HakObserverpy 0.6.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,245 @@
1
+ import psutil
2
+ import subprocess
3
+ import winreg
4
+ import json
5
+ import platform
6
+ from requests_html import HTMLSession
7
+ import traceback
8
+ from datetime import datetime
9
+
10
+ def log(Type, Message):
11
+ error_time = datetime.now().isoformat()
12
+ error_details = traceback.format_exc()
13
+
14
+ log_entry = {
15
+ "time": error_time,
16
+ "type": Type,
17
+ "details": Message
18
+ }
19
+
20
+ # Create or append to log.json
21
+ with open("log.json", "a+") as log_file:
22
+ log_file.seek(0)
23
+ if log_file.read(1):
24
+ log_file.write(",\n")
25
+ else:
26
+ log_file.write("[\n")
27
+ json.dump(log_entry, log_file, indent=4)
28
+ log_file.write("\n]")
29
+
30
+ def InitiateCollecection(HWDeviceID, ObserverVersion):
31
+
32
+ log("get_system_usage", "Starting")
33
+ get_system_usage(HWDeviceID,ObserverVersion)
34
+ log("get_system_usage", "Completed")
35
+
36
+ log("get_installed_applications", "Starting")
37
+ get_installed_applications(HWDeviceID)
38
+ log("get_installed_applications", "Completed")
39
+
40
+ collect_firewall_logs()
41
+
42
+ def collect_firewall_logs():
43
+ # Use PowerShell to collect firewall logs
44
+ powershell_command = """
45
+ $events = Get-WinEvent -LogName 'Security' -MaxEvents 100
46
+ $logs = $events | ForEach-Object { $_.Message }
47
+ $logs
48
+ """
49
+ logs = subprocess.check_output(["powershell", "-Command", powershell_command], shell=True)
50
+ return logs.decode('utf-8')
51
+
52
+ def get_installed_applications(HWDeviceID):
53
+
54
+
55
+
56
+
57
+ # Example: Retrieve installed applications and their version numbers from the Windows Registry
58
+ key = r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
59
+ installed_apps = []
60
+ with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, key) as reg_key:
61
+ for i in range(winreg.QueryInfoKey(reg_key)[0]):
62
+ try:
63
+ app_key = winreg.EnumKey(reg_key, i)
64
+ with winreg.OpenKey(reg_key, app_key) as app_reg_key:
65
+ app_name = winreg.QueryValueEx(app_reg_key, "DisplayName")[0]
66
+ app_version = winreg.QueryValueEx(app_reg_key, "DisplayVersion")[0]
67
+ app_name = str(app_name).replace("-","").replace("/","").replace("(","").replace(")","")
68
+
69
+ # Replace special characters in app_name
70
+
71
+ url = f"https://api.hakware.com/HakObserver/DeviceApps/{HWDeviceID}/{app_name}/{app_version}"
72
+
73
+ # Make a GET request to the URL
74
+ session = HTMLSession()
75
+
76
+ response = session.get(url, verify=False)
77
+
78
+ if response.status_code == 200:
79
+ print("Device Data inserted successfully via API.")
80
+ else:
81
+ print(url)
82
+ print(app_name)
83
+ print(f"Failed to insert data via API. Status code: {response.status_code}")
84
+
85
+ installed_apps.append({"name": app_name, "version": app_version})
86
+ except FileNotFoundError:
87
+ pass
88
+ return installed_apps
89
+
90
+ def get_system_usage(HWDeviceID,ObserverVersion):
91
+
92
+ # Example: Retrieve OS version using system-specific commands
93
+ os_version = str(subprocess.check_output("ver", shell=True)).replace('(', '').replace(')', '')
94
+
95
+ # Retrieve CPU, RAM, and disk usage
96
+ cpu_usage = psutil.cpu_percent()
97
+ ram_usage = psutil.virtual_memory().percent
98
+ #disk_usage = psutil.disk_usage('C:').percent # Replace 'C:' with appropriate drive letter
99
+
100
+ # Retrieve total memory
101
+ total_memory = psutil.virtual_memory().total
102
+ total_memory_gb = total_memory / (1024**3)
103
+ # Retrieve total number of CPUs and cores
104
+ total_cpus = psutil.cpu_count(logical=False) # Physical CPUs
105
+ total_cores = psutil.cpu_count(logical=True) # Logical CPUs (cores)
106
+
107
+
108
+
109
+ device_name = str(platform.node()).replace('(', '').replace(')', ''),
110
+ processor = str(platform.processor()).replace('(', '').replace(')', ''),
111
+ device_id = str(platform.node()).replace('(', '').replace(')', ''), # You may replace this with an appropriate identifier for your system
112
+ system_type = str(platform.system()).replace('(', '').replace(')', '')
113
+
114
+
115
+
116
+ ObserverVersion = str(ObserverVersion).replace("(","").replace(")","").replace(",","").replace("\\r\\n","").replace("'","")
117
+ device_id =str(device_id).replace("(","").replace(")","").replace(",","").replace("\\r\\n","").replace("'","")
118
+ device_name = str(device_name).replace("(","").replace(")","").replace(",","").replace("\\r\\n","").replace("'","")
119
+ processor = str(processor).replace("(","").replace(")","").replace(",","").replace("\\r\\n","").replace("'","")
120
+ system_type = str(system_type).replace("(","").replace(")","").replace(",","").replace("\\r\\n","").replace("'","")
121
+ os_version = str(os_version).replace("(","").replace(")","").replace(",","").replace("\\r\\n","").replace("b","").replace("'","")
122
+
123
+ print(ObserverVersion)
124
+ print(device_name)
125
+ print(processor)
126
+ print(system_type)
127
+ print(os_version)
128
+
129
+
130
+ from requests_html import HTMLSession
131
+
132
+ url = f"https://api.hakware.com/HakObserver/Device/{HWDeviceID}/{ObserverVersion}/{device_name}/{processor}/{device_id}/{system_type}/{os_version}/{total_memory_gb}/{total_cpus}/{total_cores}"
133
+
134
+
135
+
136
+ # Make a GET request to the URL
137
+ session = HTMLSession()
138
+
139
+ response = session.get(url, verify=False, timeout=10)
140
+
141
+ print(response)
142
+
143
+ if response.status_code == 200:
144
+ print("Device Data inserted successfully via API.")
145
+ else:
146
+ print(f"Failed to insert data via API. Status code: {response.status_code}")
147
+ return {
148
+ "cpu_usage_percent": cpu_usage,
149
+ "ram_usage_percent": ram_usage,
150
+ #"disk_usage_percent": disk_usage,
151
+ "total_memory": total_memory_gb,
152
+ "total_cpus": total_cpus,
153
+ "total_cores": total_cores
154
+ }
155
+
156
+
157
+ ###############################################################################################################################################################################
158
+
159
+ def LinInitiateCollecection(HWDeviceID, ObserverVersion):
160
+
161
+
162
+ get_system_usage(HWDeviceID,ObserverVersion)
163
+
164
+
165
+ get_installed_applications(HWDeviceID)
166
+
167
+
168
+ collect_firewall_logs()
169
+
170
+ def Lincollect_firewall_logs():
171
+ # Placeholder function for firewall log collection on Linux
172
+ pass
173
+
174
+ def Linget_installed_applications(HWDeviceID):
175
+ installed_apps = []
176
+
177
+ # Use dpkg-query to list installed packages
178
+ try:
179
+ dpkg_output = subprocess.check_output(["dpkg-query", "-l"], universal_newlines=True)
180
+ lines = dpkg_output.strip().split('\n')[5:] # Skip first 5 lines which are headers
181
+ for line in lines:
182
+ columns = line.split()
183
+ if len(columns) >= 2:
184
+ app_name = columns[1]
185
+ app_version = columns[2]
186
+ installed_apps.append({"name": app_name, "version": app_version})
187
+ except subprocess.CalledProcessError as e:
188
+ print("Error:", e)
189
+
190
+ # Now you can process installed_apps list as needed
191
+ for app in installed_apps:
192
+ # Replace special characters in app_name
193
+ app_name = app['name'].replace("-", "").replace("/", "").replace("(", "").replace(")", "")
194
+ app_version = app['version'].replace("-", "").replace("/", "").replace("(", "").replace(")", "").replace("'","").replace("+"," ")
195
+ # Hakware API URL for inserting installed applications
196
+ url = f"https://api.hakware.com/HakObserver/DeviceApps/{HWDeviceID}/{app_name}/{app_version}"
197
+
198
+ # Make a GET request to the URL
199
+ session = HTMLSession()
200
+ response = session.get(url, verify=False)
201
+
202
+ if response.status_code == 200:
203
+ print(f"Installed application '{app_name}' version '{app['version']}' data inserted successfully via API.")
204
+ else:
205
+ print(url)
206
+ print(f"Failed to insert installed application '{app_name}' version '{app_version}' data via API. Status code: {response.status_code}")
207
+
208
+ return installed_apps
209
+
210
+ def Linget_system_usage(HWDeviceID, ObserverVersion):
211
+ # Retrieve system information
212
+ os_version = platform.platform()
213
+ cpu_usage = psutil.cpu_percent()
214
+ ram_usage = psutil.virtual_memory().percent
215
+ total_memory = psutil.virtual_memory().total / (1024**3)
216
+ total_cpus = psutil.cpu_count(logical=False)
217
+ total_cores = psutil.cpu_count(logical=True)
218
+ device_name = platform.node()
219
+ processor = platform.processor()
220
+ device_id = platform.node()
221
+ system_type = platform.system()
222
+
223
+ if processor == '':
224
+ processor = 'unknown'
225
+
226
+ # API URL
227
+ url = f"https://api.hakware.com/HakObserver/Device/{HWDeviceID}/{ObserverVersion}/{device_name}/{processor}/{device_id}/{system_type}/{os_version}/{total_memory}/{total_cpus}/{total_cores}"
228
+
229
+ print(url)
230
+ # Make a GET request to the URL
231
+ session = HTMLSession()
232
+ response = session.get(url, verify=False, timeout=10)
233
+
234
+ if response.status_code == 200:
235
+ print("Device Data inserted successfully via API.")
236
+ else:
237
+ print(f"Failed to insert data via API. Status code: {response.status_code}")
238
+
239
+ return {
240
+ "cpu_usage_percent": cpu_usage,
241
+ "ram_usage_percent": ram_usage,
242
+ "total_memory": total_memory,
243
+ "total_cpus": total_cpus,
244
+ "total_cores": total_cores
245
+ }
@@ -0,0 +1,8 @@
1
+ # Import key functions and classes
2
+ from HakObserverpy import InitiateCollecection
3
+
4
+ # Optional: Define a version number for the package
5
+ __version__ = "0.6.2"
6
+
7
+ # Optional: Define the package's public interface
8
+ __all__ = ["InitiateCollecection"]
@@ -0,0 +1,26 @@
1
+ Metadata-Version: 2.1
2
+ Name: HakObserverpy
3
+ Version: 0.6.2
4
+ Summary: A package connect endpoints to the Hakware Application
5
+ Home-page: UNKNOWN
6
+ Author: Jacob O'Brien
7
+ License: UNKNOWN
8
+ Platform: UNKNOWN
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.6
13
+ Description-Content-Type: text/markdown
14
+
15
+ # Hakware-py
16
+
17
+ Hakware-py is a Python package that allows endpoints to connect to the Hakware solution
18
+
19
+ ## Installation
20
+
21
+ To install Hakware-py, ensure you have Python installed (version 3.6 or higher), then use pip to install the package:
22
+
23
+ ```bash
24
+ pip install Hakware-py
25
+
26
+
@@ -0,0 +1,9 @@
1
+ README.md
2
+ setup.py
3
+ HakObserverpy/HakObserverpy.py
4
+ HakObserverpy/__init__.py
5
+ HakObserverpy.egg-info/PKG-INFO
6
+ HakObserverpy.egg-info/SOURCES.txt
7
+ HakObserverpy.egg-info/dependency_links.txt
8
+ HakObserverpy.egg-info/requires.txt
9
+ HakObserverpy.egg-info/top_level.txt
@@ -0,0 +1,3 @@
1
+ requests
2
+ psutil
3
+ requests_html
@@ -0,0 +1 @@
1
+ HakObserverpy
@@ -0,0 +1,26 @@
1
+ Metadata-Version: 2.1
2
+ Name: HakObserverpy
3
+ Version: 0.6.2
4
+ Summary: A package connect endpoints to the Hakware Application
5
+ Home-page: UNKNOWN
6
+ Author: Jacob O'Brien
7
+ License: UNKNOWN
8
+ Platform: UNKNOWN
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.6
13
+ Description-Content-Type: text/markdown
14
+
15
+ # Hakware-py
16
+
17
+ Hakware-py is a Python package that allows endpoints to connect to the Hakware solution
18
+
19
+ ## Installation
20
+
21
+ To install Hakware-py, ensure you have Python installed (version 3.6 or higher), then use pip to install the package:
22
+
23
+ ```bash
24
+ pip install Hakware-py
25
+
26
+
@@ -0,0 +1,10 @@
1
+ # Hakware-py
2
+
3
+ Hakware-py is a Python package that allows endpoints to connect to the Hakware solution
4
+
5
+ ## Installation
6
+
7
+ To install Hakware-py, ensure you have Python installed (version 3.6 or higher), then use pip to install the package:
8
+
9
+ ```bash
10
+ pip install Hakware-py
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,25 @@
1
+ import platform
2
+ from setuptools import setup, find_packages
3
+
4
+ setup(
5
+ name='HakObserverpy', # Your package name
6
+ version='0.6.2', # Start with a version number
7
+ description='A package connect endpoints to the Hakware Application', # Short description
8
+ long_description=open('README.md').read(), # Long description from README
9
+ long_description_content_type='text/markdown',
10
+ author='Jacob O\'Brien', # Your name
11
+ # author_email='your.email@example.com', # Your email
12
+ # url='https://github.com/your-username/XGRCPy', # Your package's URL (if applicable)
13
+ packages=find_packages(), # Find all sub-packages
14
+ install_requires=[ # Add your package dependencies here
15
+ 'requests',
16
+ 'psutil',
17
+ 'requests_html'
18
+ ],
19
+ classifiers=[
20
+ 'Programming Language :: Python :: 3',
21
+ 'License :: OSI Approved :: MIT License', # Choose your license
22
+ 'Operating System :: OS Independent',
23
+ ],
24
+ python_requires='>=3.6', # Specify Python version compatibility
25
+ )