dbca-utils 3.0.8__tar.gz → 3.0.10__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.
Files changed (24) hide show
  1. dbca_utils-3.0.10/PKG-INFO +279 -0
  2. dbca_utils-3.0.10/README.md +251 -0
  3. {dbca_utils-3.0.8 → dbca_utils-3.0.10}/pyproject.toml +1 -1
  4. {dbca_utils-3.0.8 → dbca_utils-3.0.10}/src/dbca_utils/healthcheck/healthcheck.py +21 -14
  5. dbca_utils-3.0.8/PKG-INFO +0 -128
  6. dbca_utils-3.0.8/README.md +0 -100
  7. {dbca_utils-3.0.8 → dbca_utils-3.0.10}/LICENSE +0 -0
  8. {dbca_utils-3.0.8 → dbca_utils-3.0.10}/src/dbca_utils/__init__.py +0 -0
  9. {dbca_utils-3.0.8 → dbca_utils-3.0.10}/src/dbca_utils/apps.py +0 -0
  10. {dbca_utils-3.0.8 → dbca_utils-3.0.10}/src/dbca_utils/healthcheck/__init__.py +0 -0
  11. {dbca_utils-3.0.8 → dbca_utils-3.0.10}/src/dbca_utils/healthcheck/urls.py +0 -0
  12. {dbca_utils-3.0.8 → dbca_utils-3.0.10}/src/dbca_utils/middleware.py +0 -0
  13. {dbca_utils-3.0.8 → dbca_utils-3.0.10}/src/dbca_utils/models.py +0 -0
  14. {dbca_utils-3.0.8 → dbca_utils-3.0.10}/src/dbca_utils/utils.py +0 -0
  15. {dbca_utils-3.0.8 → dbca_utils-3.0.10}/tests/__init__.py +0 -0
  16. {dbca_utils-3.0.8 → dbca_utils-3.0.10}/tests/apps.py +0 -0
  17. {dbca_utils-3.0.8 → dbca_utils-3.0.10}/tests/migrations/0001_initial.py +0 -0
  18. {dbca_utils-3.0.8 → dbca_utils-3.0.10}/tests/migrations/__init__.py +0 -0
  19. {dbca_utils-3.0.8 → dbca_utils-3.0.10}/tests/models.py +0 -0
  20. {dbca_utils-3.0.8 → dbca_utils-3.0.10}/tests/settings.py +0 -0
  21. {dbca_utils-3.0.8 → dbca_utils-3.0.10}/tests/templates/tests/test_model_list.html +0 -0
  22. {dbca_utils-3.0.8 → dbca_utils-3.0.10}/tests/tests.py +0 -0
  23. {dbca_utils-3.0.8 → dbca_utils-3.0.10}/tests/urls.py +0 -0
  24. {dbca_utils-3.0.8 → dbca_utils-3.0.10}/tests/views.py +0 -0
@@ -0,0 +1,279 @@
1
+ Metadata-Version: 2.4
2
+ Name: dbca-utils
3
+ Version: 3.0.10
4
+ Summary: Utilities for DBCA Django apps
5
+ Author-Email: Rocky Chen <rocky.chen@dbca.wa.gov.au>, Ashley Felton <ashley.felton@dbca.wa.gov.au>
6
+ License-Expression: Apache-2.0
7
+ Classifier: Framework :: Django
8
+ Classifier: Framework :: Django :: 5.2
9
+ Classifier: Framework :: Django :: 6.0
10
+ Classifier: Environment :: Web Environment
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Programming Language :: Python
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Topic :: Software Development :: Libraries
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Project-URL: Homepage, https://github.com/dbca-wa/dbca-utils
21
+ Project-URL: Repository, https://github.com/dbca-wa/dbca-utils.git
22
+ Project-URL: Changelog, https://github.com/dbca-wa/dbca-utils/blob/main/CHANGELOG.md
23
+ Project-URL: GitHub, https://github.com/dbca-wa/dbca-utils
24
+ Requires-Python: <4.0,>=3.12
25
+ Requires-Dist: django<6.2,>=5.2
26
+ Requires-Dist: markupsafe>=3.0.3
27
+ Description-Content-Type: text/markdown
28
+
29
+ # Overview
30
+
31
+ DBCA Django utility classes and functions.
32
+
33
+ ## Requirements
34
+
35
+ - Python 3.12 or later
36
+ - Django 5.2 or later
37
+
38
+ ## Development
39
+
40
+ Dependencies for this project are managed using [uv](https://docs.astral.sh/uv/).
41
+ With uv installed, change into the project directory and run:
42
+
43
+ uv sync
44
+
45
+ Activate the virtualenv like so:
46
+
47
+ source .venv/bin/activate
48
+
49
+ Run unit tests using `pytest` (or `tox`, to test against multiple Python versions):
50
+
51
+ pytest -sv
52
+ tox -v
53
+
54
+ ## Releases
55
+
56
+ Tagged releases are built and pushed to PyPI automatically using a GitHub
57
+ workflow in the project. Update the project version in `pyproject.toml` and
58
+ tag the required commit with the same value to trigger a release. Packages
59
+ can also be built and uploaded manually to PyPI using [uv](https://docs.astral.sh/uv/guides/publish/#publishing-your-package),
60
+ if required:
61
+
62
+ uv build
63
+ uv publish
64
+
65
+ ## Installation
66
+
67
+ 1. Install via uv/pip/etc.: `pip install dbca-utils`
68
+
69
+ ## SSO Login Middleware
70
+
71
+ This will automatically login and create users using headers from an upstream proxy (REMOTE_USER and some others).
72
+ The logout view will redirect to a separate logout page which clears the SSO session.
73
+
74
+ ### Usage
75
+
76
+ Add `dbca_utils.middleware.SSOLoginMiddleware` to `settings.MIDDLEWARE` (after both of
77
+ `django.contrib.sessions.middleware.SessionMiddleware` and
78
+ `django.contrib.auth.middleware.AuthenticationMiddleware`.
79
+ Ensure that `AUTHENTICATION_BACKENDS` contains `django.contrib.auth.backends.ModelBackend`,
80
+ as this middleware depends on it for retrieving the logged in user for a session.
81
+ Note that the middleware will still work without it, but will reauthenticate the session
82
+ on every request, and `request.user.is_authenticated` won't work properly/will be false.
83
+
84
+ Example:
85
+
86
+ ```python
87
+ MIDDLEWARE = [
88
+ ...,
89
+ 'django.contrib.sessions.middleware.SessionMiddleware',
90
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
91
+ 'dbca_utils.middleware.SSOLoginMiddleware'
92
+ ...,
93
+ ]
94
+ ```
95
+
96
+ ## Audit model mixin
97
+
98
+ `AuditMixin` is an extension of `Django.db.model.Model` that adds a number of additional fields:
99
+
100
+ - `creator` - FK to `AUTH_USER_MODEL`, used to record the object creator
101
+ - `modifier` - FK to `AUTH_USER_MODEL`, used to record who the object was last modified by
102
+ - `created` - a timestamp that is set on initial object save
103
+ - `modified` - an auto-updating timestamp (on each object save)
104
+
105
+ ## Healthcheck feature
106
+ ### Requirements
107
+ - Django 5.2 or later
108
+ - Declared the default cache and also the cache is shared by all pod instances
109
+
110
+ ### Usage
111
+ - Install the app 'dbca_utils' in INSTALLED_APPS
112
+ - Service Configuration
113
+ - HEALTHCHECK_ENABLED: Optional. enable/disable the healthcheck service. default is 'true'
114
+ - CACHE_PREFIX: Optional. used as the prefix of the cache key. default is ''
115
+ - PORT: Optional. The listening port of the web application. default is '8080', used to send request to peer pod instance to get the resouces usage of the peer pod instance.
116
+ - WORKLOADS: Optional. Used if the web app has a fixed replicas.
117
+ - WORKLOAD_DEPLOYMENT: Optional. the workload is deployment if it is true; otherwise it is statefulset. default is 'true'
118
+ - WORKLOAD_FAILED_THRESHOLD: Optional. The number of continuous failed times to decide that a pod is offline.
119
+ - WORKLOAD_VOLUMES: Optional. can be 'disabled', 'false','automatic' or "," separated volume mounted point. default is "automatic".
120
+ - disabled|false: Don't harvest volume usage data
121
+ - automatic: Detect the persistent volume automatically.
122
+ - "," separated volume mounted points: the volume list
123
+ - HEALTHCHECK_SYSTEMDATA_ENABLED: Enable system resource data
124
+ - HEALTHCHECK_PROCESSDATA_ENABLED: Enable process resource data
125
+ - Endpoints added by this app
126
+ - /healthcheck/healthdata: An endpoint for client to harvest the resources usage data. This endpoint should be cofigured to use basic auth in nginx reverse proxy.
127
+ - /workload/healthcheck/healthdata: An internal endpoint used to get the resource usage of the peer pod instance. This endpoing should not be exposed in nginx reverse proxy.
128
+ - Nginx Configuration.
129
+ - Add a location 'location /healthcheck/' and configure it to use basic auth in nginx.
130
+ - Access the url : https://xxx.dbca.wa.gov.au/healthcheck/healthdata to get the health json data
131
+ - The sample data of the health data:
132
+
133
+ {
134
+ "workload0":{
135
+ "resources":{
136
+ "start_time":"2026-07-24T06:10:23",
137
+ "cpu_total":0.0,
138
+ "cpu_min":0.0,
139
+ "cpu_max":0.0,
140
+ "pmemory_total":292.28125,
141
+ "pmemory_min":95.53515625,
142
+ "pmemory_max":100.828125,
143
+ "vmemory_total":764.12890625,
144
+ "vmemory_min":207.8671875,
145
+ "vmemory_max":278.59765625,
146
+ "processes":3,
147
+ "process":{
148
+ "start_time":"2026-07-24T06:10:23",
149
+ "cpu_num":0,
150
+ "cpu_pcent":0.0,
151
+ "pmemory":100.828125,
152
+ "vmemory":207.8671875,
153
+ "children":[
154
+ {
155
+ "start_time":"2026-07-24T06:10:24",
156
+ "cpu_num":1,
157
+ "cpu_pcent":0.0,
158
+ "pmemory":95.53515625,
159
+ "vmemory":277.6640625
160
+ },
161
+ {
162
+ "start_time":"2026-07-24T06:10:24",
163
+ "cpu_num":3,
164
+ "cpu_pcent":0.0,
165
+ "pmemory":95.91796875,
166
+ "vmemory":278.59765625,
167
+ "currentprocess":true
168
+ }
169
+ ]
170
+ }
171
+ },
172
+ "system":{
173
+ "cpu_pcent":0.0,
174
+ "cpucores_pcent":[
175
+ 0.0,
176
+ 0.0,
177
+ 0.0,
178
+ 0.0
179
+ ],
180
+ "memory_total":31.279705047607422,
181
+ "memory_used":12.220211029052734,
182
+ "memory_pcent":39.06753919339612,
183
+ "bytes_sent":9028205,
184
+ "bytes_recv":9246094
185
+ },
186
+ "volumes":{
187
+ "/app/captcha":{
188
+ "size":1024,
189
+ "used":0,
190
+ "pcent":0.006103515625,
191
+ "unit":"M"
192
+ }
193
+ },
194
+ "hostname":"auth2-uat11-5b495b67cb-z8vwj"
195
+ },
196
+ "workload1":{
197
+ "resources":{
198
+ "start_time":"2026-07-24T06:11:45",
199
+ "cpu_total":0.0,
200
+ "cpu_min":0.0,
201
+ "cpu_max":0.0,
202
+ "pmemory_total":292.02734375,
203
+ "pmemory_min":95.4140625,
204
+ "pmemory_max":100.6171875,
205
+ "vmemory_total":763.84375,
206
+ "vmemory_min":207.8359375,
207
+ "vmemory_max":278.546875,
208
+ "processes":3,
209
+ "process":{
210
+ "start_time":"2026-07-24T06:11:45",
211
+ "cpu_num":1,
212
+ "cpu_pcent":0.0,
213
+ "pmemory":100.6171875,
214
+ "vmemory":207.8359375,
215
+ "children":[
216
+ {
217
+ "start_time":"2026-07-24T06:11:46",
218
+ "cpu_num":2,
219
+ "cpu_pcent":0.0,
220
+ "pmemory":95.4140625,
221
+ "vmemory":277.4609375
222
+ },
223
+ {
224
+ "start_time":"2026-07-24T06:11:46",
225
+ "cpu_num":3,
226
+ "cpu_pcent":0.0,
227
+ "pmemory":95.99609375,
228
+ "vmemory":278.546875,
229
+ }
230
+ ]
231
+ }
232
+ },
233
+ "system":{
234
+ "cpu_pcent":13.1,
235
+ "cpucores_pcent":[
236
+ 15.4,
237
+ 12.2,
238
+ 12.0,
239
+ 12.7
240
+ ],
241
+ "memory_total":31.279705047607422,
242
+ "memory_used":12.220211029052734,
243
+ "memory_pcent":39.06753919339612,
244
+ "bytes_sent":9099207,
245
+ "bytes_recv":9055029
246
+ },
247
+ "volumes":{
248
+ "/app/captcha":{
249
+ "size":1024,
250
+ "used":0,
251
+ "pcent":0.006103515625,
252
+ "unit":"M"
253
+ }
254
+ },
255
+ "hostname":"auth2-uat11-5b495b67cb-dpdjp"
256
+ },
257
+ "summary":{
258
+ "cpu_total":0.0,
259
+ "cpu_min":0.0,
260
+ "cpu_max":0.0,
261
+ "process_cpu_min":0.0,
262
+ "process_cpu_max":0.0,
263
+ "pmemory_total":584.30859375,
264
+ "pmemory_min":292.02734375,
265
+ "pmemory_max":292.28125,
266
+ "process_pmemory_min":95.4140625,
267
+ "process_pmemory_max":100.828125,
268
+ "vmemory_total":1527.97265625,
269
+ "vmemory_min":763.84375,
270
+ "vmemory_max":764.12890625,
271
+ "process_vmemory_min":207.8359375,
272
+ "process_vmemory_max":278.59765625,
273
+ "processes_total":6,
274
+ "workloads_running":2,
275
+ "workloads_failed":0
276
+ }
277
+ }
278
+
279
+
@@ -0,0 +1,251 @@
1
+ # Overview
2
+
3
+ DBCA Django utility classes and functions.
4
+
5
+ ## Requirements
6
+
7
+ - Python 3.12 or later
8
+ - Django 5.2 or later
9
+
10
+ ## Development
11
+
12
+ Dependencies for this project are managed using [uv](https://docs.astral.sh/uv/).
13
+ With uv installed, change into the project directory and run:
14
+
15
+ uv sync
16
+
17
+ Activate the virtualenv like so:
18
+
19
+ source .venv/bin/activate
20
+
21
+ Run unit tests using `pytest` (or `tox`, to test against multiple Python versions):
22
+
23
+ pytest -sv
24
+ tox -v
25
+
26
+ ## Releases
27
+
28
+ Tagged releases are built and pushed to PyPI automatically using a GitHub
29
+ workflow in the project. Update the project version in `pyproject.toml` and
30
+ tag the required commit with the same value to trigger a release. Packages
31
+ can also be built and uploaded manually to PyPI using [uv](https://docs.astral.sh/uv/guides/publish/#publishing-your-package),
32
+ if required:
33
+
34
+ uv build
35
+ uv publish
36
+
37
+ ## Installation
38
+
39
+ 1. Install via uv/pip/etc.: `pip install dbca-utils`
40
+
41
+ ## SSO Login Middleware
42
+
43
+ This will automatically login and create users using headers from an upstream proxy (REMOTE_USER and some others).
44
+ The logout view will redirect to a separate logout page which clears the SSO session.
45
+
46
+ ### Usage
47
+
48
+ Add `dbca_utils.middleware.SSOLoginMiddleware` to `settings.MIDDLEWARE` (after both of
49
+ `django.contrib.sessions.middleware.SessionMiddleware` and
50
+ `django.contrib.auth.middleware.AuthenticationMiddleware`.
51
+ Ensure that `AUTHENTICATION_BACKENDS` contains `django.contrib.auth.backends.ModelBackend`,
52
+ as this middleware depends on it for retrieving the logged in user for a session.
53
+ Note that the middleware will still work without it, but will reauthenticate the session
54
+ on every request, and `request.user.is_authenticated` won't work properly/will be false.
55
+
56
+ Example:
57
+
58
+ ```python
59
+ MIDDLEWARE = [
60
+ ...,
61
+ 'django.contrib.sessions.middleware.SessionMiddleware',
62
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
63
+ 'dbca_utils.middleware.SSOLoginMiddleware'
64
+ ...,
65
+ ]
66
+ ```
67
+
68
+ ## Audit model mixin
69
+
70
+ `AuditMixin` is an extension of `Django.db.model.Model` that adds a number of additional fields:
71
+
72
+ - `creator` - FK to `AUTH_USER_MODEL`, used to record the object creator
73
+ - `modifier` - FK to `AUTH_USER_MODEL`, used to record who the object was last modified by
74
+ - `created` - a timestamp that is set on initial object save
75
+ - `modified` - an auto-updating timestamp (on each object save)
76
+
77
+ ## Healthcheck feature
78
+ ### Requirements
79
+ - Django 5.2 or later
80
+ - Declared the default cache and also the cache is shared by all pod instances
81
+
82
+ ### Usage
83
+ - Install the app 'dbca_utils' in INSTALLED_APPS
84
+ - Service Configuration
85
+ - HEALTHCHECK_ENABLED: Optional. enable/disable the healthcheck service. default is 'true'
86
+ - CACHE_PREFIX: Optional. used as the prefix of the cache key. default is ''
87
+ - PORT: Optional. The listening port of the web application. default is '8080', used to send request to peer pod instance to get the resouces usage of the peer pod instance.
88
+ - WORKLOADS: Optional. Used if the web app has a fixed replicas.
89
+ - WORKLOAD_DEPLOYMENT: Optional. the workload is deployment if it is true; otherwise it is statefulset. default is 'true'
90
+ - WORKLOAD_FAILED_THRESHOLD: Optional. The number of continuous failed times to decide that a pod is offline.
91
+ - WORKLOAD_VOLUMES: Optional. can be 'disabled', 'false','automatic' or "," separated volume mounted point. default is "automatic".
92
+ - disabled|false: Don't harvest volume usage data
93
+ - automatic: Detect the persistent volume automatically.
94
+ - "," separated volume mounted points: the volume list
95
+ - HEALTHCHECK_SYSTEMDATA_ENABLED: Enable system resource data
96
+ - HEALTHCHECK_PROCESSDATA_ENABLED: Enable process resource data
97
+ - Endpoints added by this app
98
+ - /healthcheck/healthdata: An endpoint for client to harvest the resources usage data. This endpoint should be cofigured to use basic auth in nginx reverse proxy.
99
+ - /workload/healthcheck/healthdata: An internal endpoint used to get the resource usage of the peer pod instance. This endpoing should not be exposed in nginx reverse proxy.
100
+ - Nginx Configuration.
101
+ - Add a location 'location /healthcheck/' and configure it to use basic auth in nginx.
102
+ - Access the url : https://xxx.dbca.wa.gov.au/healthcheck/healthdata to get the health json data
103
+ - The sample data of the health data:
104
+
105
+ {
106
+ "workload0":{
107
+ "resources":{
108
+ "start_time":"2026-07-24T06:10:23",
109
+ "cpu_total":0.0,
110
+ "cpu_min":0.0,
111
+ "cpu_max":0.0,
112
+ "pmemory_total":292.28125,
113
+ "pmemory_min":95.53515625,
114
+ "pmemory_max":100.828125,
115
+ "vmemory_total":764.12890625,
116
+ "vmemory_min":207.8671875,
117
+ "vmemory_max":278.59765625,
118
+ "processes":3,
119
+ "process":{
120
+ "start_time":"2026-07-24T06:10:23",
121
+ "cpu_num":0,
122
+ "cpu_pcent":0.0,
123
+ "pmemory":100.828125,
124
+ "vmemory":207.8671875,
125
+ "children":[
126
+ {
127
+ "start_time":"2026-07-24T06:10:24",
128
+ "cpu_num":1,
129
+ "cpu_pcent":0.0,
130
+ "pmemory":95.53515625,
131
+ "vmemory":277.6640625
132
+ },
133
+ {
134
+ "start_time":"2026-07-24T06:10:24",
135
+ "cpu_num":3,
136
+ "cpu_pcent":0.0,
137
+ "pmemory":95.91796875,
138
+ "vmemory":278.59765625,
139
+ "currentprocess":true
140
+ }
141
+ ]
142
+ }
143
+ },
144
+ "system":{
145
+ "cpu_pcent":0.0,
146
+ "cpucores_pcent":[
147
+ 0.0,
148
+ 0.0,
149
+ 0.0,
150
+ 0.0
151
+ ],
152
+ "memory_total":31.279705047607422,
153
+ "memory_used":12.220211029052734,
154
+ "memory_pcent":39.06753919339612,
155
+ "bytes_sent":9028205,
156
+ "bytes_recv":9246094
157
+ },
158
+ "volumes":{
159
+ "/app/captcha":{
160
+ "size":1024,
161
+ "used":0,
162
+ "pcent":0.006103515625,
163
+ "unit":"M"
164
+ }
165
+ },
166
+ "hostname":"auth2-uat11-5b495b67cb-z8vwj"
167
+ },
168
+ "workload1":{
169
+ "resources":{
170
+ "start_time":"2026-07-24T06:11:45",
171
+ "cpu_total":0.0,
172
+ "cpu_min":0.0,
173
+ "cpu_max":0.0,
174
+ "pmemory_total":292.02734375,
175
+ "pmemory_min":95.4140625,
176
+ "pmemory_max":100.6171875,
177
+ "vmemory_total":763.84375,
178
+ "vmemory_min":207.8359375,
179
+ "vmemory_max":278.546875,
180
+ "processes":3,
181
+ "process":{
182
+ "start_time":"2026-07-24T06:11:45",
183
+ "cpu_num":1,
184
+ "cpu_pcent":0.0,
185
+ "pmemory":100.6171875,
186
+ "vmemory":207.8359375,
187
+ "children":[
188
+ {
189
+ "start_time":"2026-07-24T06:11:46",
190
+ "cpu_num":2,
191
+ "cpu_pcent":0.0,
192
+ "pmemory":95.4140625,
193
+ "vmemory":277.4609375
194
+ },
195
+ {
196
+ "start_time":"2026-07-24T06:11:46",
197
+ "cpu_num":3,
198
+ "cpu_pcent":0.0,
199
+ "pmemory":95.99609375,
200
+ "vmemory":278.546875,
201
+ }
202
+ ]
203
+ }
204
+ },
205
+ "system":{
206
+ "cpu_pcent":13.1,
207
+ "cpucores_pcent":[
208
+ 15.4,
209
+ 12.2,
210
+ 12.0,
211
+ 12.7
212
+ ],
213
+ "memory_total":31.279705047607422,
214
+ "memory_used":12.220211029052734,
215
+ "memory_pcent":39.06753919339612,
216
+ "bytes_sent":9099207,
217
+ "bytes_recv":9055029
218
+ },
219
+ "volumes":{
220
+ "/app/captcha":{
221
+ "size":1024,
222
+ "used":0,
223
+ "pcent":0.006103515625,
224
+ "unit":"M"
225
+ }
226
+ },
227
+ "hostname":"auth2-uat11-5b495b67cb-dpdjp"
228
+ },
229
+ "summary":{
230
+ "cpu_total":0.0,
231
+ "cpu_min":0.0,
232
+ "cpu_max":0.0,
233
+ "process_cpu_min":0.0,
234
+ "process_cpu_max":0.0,
235
+ "pmemory_total":584.30859375,
236
+ "pmemory_min":292.02734375,
237
+ "pmemory_max":292.28125,
238
+ "process_pmemory_min":95.4140625,
239
+ "process_pmemory_max":100.828125,
240
+ "vmemory_total":1527.97265625,
241
+ "vmemory_min":763.84375,
242
+ "vmemory_max":764.12890625,
243
+ "process_vmemory_min":207.8359375,
244
+ "process_vmemory_max":278.59765625,
245
+ "processes_total":6,
246
+ "workloads_running":2,
247
+ "workloads_failed":0
248
+ }
249
+ }
250
+
251
+
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "dbca-utils"
3
- version = "3.0.8"
3
+ version = "3.0.10"
4
4
  description = "Utilities for DBCA Django apps"
5
5
  authors = [
6
6
  { name = "Rocky Chen", email = "rocky.chen@dbca.wa.gov.au" },
@@ -88,7 +88,7 @@ item_version = "__version__"
88
88
  key_workloads = "{}__workloads__".format(CACHE_PREFIX)
89
89
  key_workloads_lock = "{}lock__".format(key_workloads)
90
90
 
91
- def register_webappserver(sender,*args,**kwargs):
91
+ def register_webappserver(*args,**kwargs):
92
92
  """
93
93
  Register a web server running in the same workload
94
94
  1. Write a server register file in workload's local file system
@@ -214,14 +214,16 @@ def get_process_healthdata(proc):
214
214
  memoryinfo = proc.memory_info()
215
215
  result = {
216
216
  "start_time":timezone.make_aware(datetime.fromtimestamp(proc.create_time())).strftime("%Y-%m-%dT%H:%M:%S"),
217
- "cmdline":proc.cmdline(),
218
217
  "cpu_num": proc.cpu_num(),
219
218
  "cpu_pcent": proc.cpu_percent(),
220
219
  "pmemory":memoryinfo.rss / 1048576,
221
220
  "vmemory":memoryinfo.vms / 1048576
222
221
  }
223
- if proc.pid == curprocpid:
224
- result["currentprocess"] = True
222
+ if settings.DEBUG:
223
+ result["cmdline"] = proc.cmdline()
224
+ if proc.pid == curprocpid:
225
+ result["currentprocess"] = True
226
+
225
227
  return result
226
228
 
227
229
  rootproc = None
@@ -320,17 +322,19 @@ def get_workload_app_healthdata(perprocess=True):
320
322
  return result
321
323
 
322
324
  def get_workload_healthdata():
325
+ try:
326
+ result = {
327
+ "resources": get_workload_app_healthdata(HEALTHCHECK_PROCESSDATA_ENABLED)
328
+ }
329
+ if HEALTHCHECK_SYSTEMDATA_ENABLED:
330
+ result["system"] = get_workload_system_healthdata()
323
331
 
324
- result = {
325
- "resources": get_workload_app_healthdata(HEALTHCHECK_PROCESSDATA_ENABLED)
326
- }
327
- if HEALTHCHECK_SYSTEMDATA_ENABLED:
328
- result["system"] = get_workload_system_healthdata()
329
-
330
- if WORKLOAD_VOLUMES_ENABLED:
331
- result["volumes"] = get_volumes_healthdata()
332
+ if WORKLOAD_VOLUMES_ENABLED:
333
+ result["volumes"] = get_volumes_healthdata()
332
334
 
333
- return (200,result)
335
+ return (200,result)
336
+ except Exception as ex:
337
+ return (500,"{}:{}".format(ex.__classs__.__name__,str(ex)))
334
338
 
335
339
  bearer_token_re = re.compile("^Bearer\\s+(?P<token>\\S+)\\s*$")
336
340
  def get_auth_bearer(request):
@@ -456,6 +460,9 @@ def populate_summary_data(datas):
456
460
  "workloads_running":0,
457
461
  "workloads_failed":0,
458
462
  }
463
+ if settings.DEBUG:
464
+ summary["currentworkload"] = registerhostname
465
+
459
466
  for servername,serverdata in datas.items():
460
467
  if isinstance(serverdata,str):
461
468
  summary["workloads_failed"] += 1
@@ -738,7 +745,7 @@ def workload_healthdata_view(request):
738
745
  if statuscode == 200:
739
746
  return JsonResponse(data)
740
747
  else:
741
- return JsonResponse({"status":500,"message":"Server Error"},status=599)
748
+ return JsonResponse({"status":statuscode,"message":data},status=599)
742
749
  except Exception as ex:
743
750
  return JsonResponse({"status":500,"message":"{}:{}".format(ex.__class__.__name__,str(ex))},status=599)
744
751
 
dbca_utils-3.0.8/PKG-INFO DELETED
@@ -1,128 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: dbca-utils
3
- Version: 3.0.8
4
- Summary: Utilities for DBCA Django apps
5
- Author-Email: Rocky Chen <rocky.chen@dbca.wa.gov.au>, Ashley Felton <ashley.felton@dbca.wa.gov.au>
6
- License-Expression: Apache-2.0
7
- Classifier: Framework :: Django
8
- Classifier: Framework :: Django :: 5.2
9
- Classifier: Framework :: Django :: 6.0
10
- Classifier: Environment :: Web Environment
11
- Classifier: Intended Audience :: Developers
12
- Classifier: Development Status :: 5 - Production/Stable
13
- Classifier: Programming Language :: Python
14
- Classifier: Programming Language :: Python :: 3
15
- Classifier: Programming Language :: Python :: 3.12
16
- Classifier: Programming Language :: Python :: 3.13
17
- Classifier: Programming Language :: Python :: 3.14
18
- Classifier: Topic :: Software Development :: Libraries
19
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
- Project-URL: Homepage, https://github.com/dbca-wa/dbca-utils
21
- Project-URL: Repository, https://github.com/dbca-wa/dbca-utils.git
22
- Project-URL: Changelog, https://github.com/dbca-wa/dbca-utils/blob/main/CHANGELOG.md
23
- Project-URL: GitHub, https://github.com/dbca-wa/dbca-utils
24
- Requires-Python: <4.0,>=3.12
25
- Requires-Dist: django<6.2,>=5.2
26
- Requires-Dist: markupsafe>=3.0.3
27
- Description-Content-Type: text/markdown
28
-
29
- # Overview
30
-
31
- DBCA Django utility classes and functions.
32
-
33
- ## Requirements
34
-
35
- - Python 3.12 or later
36
- - Django 5.2 or later
37
-
38
- ## Development
39
-
40
- Dependencies for this project are managed using [uv](https://docs.astral.sh/uv/).
41
- With uv installed, change into the project directory and run:
42
-
43
- uv sync
44
-
45
- Activate the virtualenv like so:
46
-
47
- source .venv/bin/activate
48
-
49
- Run unit tests using `pytest` (or `tox`, to test against multiple Python versions):
50
-
51
- pytest -sv
52
- tox -v
53
-
54
- ## Releases
55
-
56
- Tagged releases are built and pushed to PyPI automatically using a GitHub
57
- workflow in the project. Update the project version in `pyproject.toml` and
58
- tag the required commit with the same value to trigger a release. Packages
59
- can also be built and uploaded manually to PyPI using [uv](https://docs.astral.sh/uv/guides/publish/#publishing-your-package),
60
- if required:
61
-
62
- uv build
63
- uv publish
64
-
65
- ## Installation
66
-
67
- 1. Install via uv/pip/etc.: `pip install dbca-utils`
68
-
69
- ## SSO Login Middleware
70
-
71
- This will automatically login and create users using headers from an upstream proxy (REMOTE_USER and some others).
72
- The logout view will redirect to a separate logout page which clears the SSO session.
73
-
74
- ### Usage
75
-
76
- Add `dbca_utils.middleware.SSOLoginMiddleware` to `settings.MIDDLEWARE` (after both of
77
- `django.contrib.sessions.middleware.SessionMiddleware` and
78
- `django.contrib.auth.middleware.AuthenticationMiddleware`.
79
- Ensure that `AUTHENTICATION_BACKENDS` contains `django.contrib.auth.backends.ModelBackend`,
80
- as this middleware depends on it for retrieving the logged in user for a session.
81
- Note that the middleware will still work without it, but will reauthenticate the session
82
- on every request, and `request.user.is_authenticated` won't work properly/will be false.
83
-
84
- Example:
85
-
86
- ```python
87
- MIDDLEWARE = [
88
- ...,
89
- 'django.contrib.sessions.middleware.SessionMiddleware',
90
- 'django.contrib.auth.middleware.AuthenticationMiddleware',
91
- 'dbca_utils.middleware.SSOLoginMiddleware'
92
- ...,
93
- ]
94
- ```
95
-
96
- ## Audit model mixin
97
-
98
- `AuditMixin` is an extension of `Django.db.model.Model` that adds a number of additional fields:
99
-
100
- - `creator` - FK to `AUTH_USER_MODEL`, used to record the object creator
101
- - `modifier` - FK to `AUTH_USER_MODEL`, used to record who the object was last modified by
102
- - `created` - a timestamp that is set on initial object save
103
- - `modified` - an auto-updating timestamp (on each object save)
104
-
105
- ## Healthcheck feature
106
- ### Requirements
107
- - Django 5.2 or later
108
- - Declared the default cache and also the cache is shared by all pod instances
109
- - The image has the command 'ps' which is used to collect the cpu,memory and persistent volume usage data.
110
-
111
- ### Usage
112
- - Install the app 'dbca_utils' in INSTALLED_APPS
113
- - Service Configuration
114
- - HEALTHCHECK_ENABLED: Optional. enable/disable the healthcheck service. default is 'true'
115
- - CACHE_PREFIX: Optional. used as the prefix WORKLOAD_VOLUMESof WORKLOAD_VOLUMESthe cache key. default is ''
116
- - PORT: Optional. The listening port of the web application. default is '8080'
117
- - WORKLOADS: Optional. Used if the web app has a fixed replicas.
118
- - WORKLOAD_DEPLOYMENT: Optional. the workload is deployment if it is true; otherwise it is statefulset. default is 'true'
119
- - WORKLOAD_FAILED_THRESHOLD: Optional. The number of continuous failed times to treat a pod is offline.
120
- - WORKLOAD_VOLUMES: Optional. can be 'disabled', 'false','automatic' or "," separated volume mounted point. default is "automatic".
121
- - disabled|false: Don't harvest volume usage data
122
- - automatic: Detect the persistent volume automatically.
123
- - "," separated volume mounted points: the volume list
124
- - HEALTHCHECK_SYSTEMDATA_ENABLED: Enable system resource data
125
- - HEALTHCHECK_PROCESSDATA_ENABLED: Enable process resource data
126
- - Nginx Configuration.
127
- - Add a location 'location /healthcheck/' and configure it to use basic auth in nginx.
128
- - Access the url : https://xxx.dbca.wa.gov.au/healthcheck/healthdata to get the health json data
@@ -1,100 +0,0 @@
1
- # Overview
2
-
3
- DBCA Django utility classes and functions.
4
-
5
- ## Requirements
6
-
7
- - Python 3.12 or later
8
- - Django 5.2 or later
9
-
10
- ## Development
11
-
12
- Dependencies for this project are managed using [uv](https://docs.astral.sh/uv/).
13
- With uv installed, change into the project directory and run:
14
-
15
- uv sync
16
-
17
- Activate the virtualenv like so:
18
-
19
- source .venv/bin/activate
20
-
21
- Run unit tests using `pytest` (or `tox`, to test against multiple Python versions):
22
-
23
- pytest -sv
24
- tox -v
25
-
26
- ## Releases
27
-
28
- Tagged releases are built and pushed to PyPI automatically using a GitHub
29
- workflow in the project. Update the project version in `pyproject.toml` and
30
- tag the required commit with the same value to trigger a release. Packages
31
- can also be built and uploaded manually to PyPI using [uv](https://docs.astral.sh/uv/guides/publish/#publishing-your-package),
32
- if required:
33
-
34
- uv build
35
- uv publish
36
-
37
- ## Installation
38
-
39
- 1. Install via uv/pip/etc.: `pip install dbca-utils`
40
-
41
- ## SSO Login Middleware
42
-
43
- This will automatically login and create users using headers from an upstream proxy (REMOTE_USER and some others).
44
- The logout view will redirect to a separate logout page which clears the SSO session.
45
-
46
- ### Usage
47
-
48
- Add `dbca_utils.middleware.SSOLoginMiddleware` to `settings.MIDDLEWARE` (after both of
49
- `django.contrib.sessions.middleware.SessionMiddleware` and
50
- `django.contrib.auth.middleware.AuthenticationMiddleware`.
51
- Ensure that `AUTHENTICATION_BACKENDS` contains `django.contrib.auth.backends.ModelBackend`,
52
- as this middleware depends on it for retrieving the logged in user for a session.
53
- Note that the middleware will still work without it, but will reauthenticate the session
54
- on every request, and `request.user.is_authenticated` won't work properly/will be false.
55
-
56
- Example:
57
-
58
- ```python
59
- MIDDLEWARE = [
60
- ...,
61
- 'django.contrib.sessions.middleware.SessionMiddleware',
62
- 'django.contrib.auth.middleware.AuthenticationMiddleware',
63
- 'dbca_utils.middleware.SSOLoginMiddleware'
64
- ...,
65
- ]
66
- ```
67
-
68
- ## Audit model mixin
69
-
70
- `AuditMixin` is an extension of `Django.db.model.Model` that adds a number of additional fields:
71
-
72
- - `creator` - FK to `AUTH_USER_MODEL`, used to record the object creator
73
- - `modifier` - FK to `AUTH_USER_MODEL`, used to record who the object was last modified by
74
- - `created` - a timestamp that is set on initial object save
75
- - `modified` - an auto-updating timestamp (on each object save)
76
-
77
- ## Healthcheck feature
78
- ### Requirements
79
- - Django 5.2 or later
80
- - Declared the default cache and also the cache is shared by all pod instances
81
- - The image has the command 'ps' which is used to collect the cpu,memory and persistent volume usage data.
82
-
83
- ### Usage
84
- - Install the app 'dbca_utils' in INSTALLED_APPS
85
- - Service Configuration
86
- - HEALTHCHECK_ENABLED: Optional. enable/disable the healthcheck service. default is 'true'
87
- - CACHE_PREFIX: Optional. used as the prefix WORKLOAD_VOLUMESof WORKLOAD_VOLUMESthe cache key. default is ''
88
- - PORT: Optional. The listening port of the web application. default is '8080'
89
- - WORKLOADS: Optional. Used if the web app has a fixed replicas.
90
- - WORKLOAD_DEPLOYMENT: Optional. the workload is deployment if it is true; otherwise it is statefulset. default is 'true'
91
- - WORKLOAD_FAILED_THRESHOLD: Optional. The number of continuous failed times to treat a pod is offline.
92
- - WORKLOAD_VOLUMES: Optional. can be 'disabled', 'false','automatic' or "," separated volume mounted point. default is "automatic".
93
- - disabled|false: Don't harvest volume usage data
94
- - automatic: Detect the persistent volume automatically.
95
- - "," separated volume mounted points: the volume list
96
- - HEALTHCHECK_SYSTEMDATA_ENABLED: Enable system resource data
97
- - HEALTHCHECK_PROCESSDATA_ENABLED: Enable process resource data
98
- - Nginx Configuration.
99
- - Add a location 'location /healthcheck/' and configure it to use basic auth in nginx.
100
- - Access the url : https://xxx.dbca.wa.gov.au/healthcheck/healthdata to get the health json data
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes