Skip to content

Commit 817c29f

Browse files
authored
Adding support for opensearch (#7)
1 parent 240389b commit 817c29f

File tree

5 files changed

+221
-54
lines changed

5 files changed

+221
-54
lines changed

Dockerfile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
FROM alpine:3.21.0
1+
FROM alpine:3.21.3
22

3-
LABEL maintainer="Michael Oberdorf IT-Consulting <info@oberdorf-itc.de>"
4-
LABEL site.local.program.version="1.1.1"
3+
LABEL maintainer="Michael Oberdorf IT-Consulting <info@oberdorf-itc.de>" \
4+
site.local.program.version="1.2.0"
55

66
ENV CONFIG_FILE=/app/etc/mqtt2elasticsearch.json \
7-
ELASTICSEARCH_MAPPING_FILE=/app/etc/mqtt2elasticsearch-mappings.json
7+
ELASTICSEARCH_MAPPING_FILE=/app/etc/mqtt2elasticsearch-mappings.json \
8+
REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
89

910
COPY --chown=root:root /src /
1011

1112
RUN apk upgrade --available --no-cache --update \
1213
&& apk add --no-cache --update \
13-
python3=3.12.8-r1 \
14+
python3=3.12.9-r0 \
1415
py3-pip=24.3.1-r0 \
16+
ca-certificates=20241121-r1 \
1517
&& pip3 install --no-cache-dir -r /requirements.txt --break-system-packages
1618

1719
USER 6352:6352

README.md

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,20 @@ Container image: [DockerHub](https://hub.docker.com/repository/docker/oitc/mqtt2
2323

2424
# Supported tags and respective `Dockerfile` links
2525

26-
* [`latest`, `1.1.1`](https://github.com/cybcon/docker.mqtt2elasticsearch/blob/v1.1.1/Dockerfile)
26+
* [`latest`, `1.2.0`](https://github.com/cybcon/docker.mqtt2elasticsearch/blob/v1.2.0/Dockerfile)
27+
* [`1.1.1`](https://github.com/cybcon/docker.mqtt2elasticsearch/blob/v1.1.1/Dockerfile)
2728
* [`1.1.0`](https://github.com/cybcon/docker.mqtt2elasticsearch/blob/v1.1.0/Dockerfile)
2829
* [`1.0.0`](https://github.com/cybcon/docker.mqtt2elasticsearch/blob/v1.0.0/Dockerfile)
2930

3031
# Summary
3132

3233
The container image is based on Alpine Linux with python3 interpreter.
3334
The tool is written in python and connects to a MQTT server and subscripes to one ore more topics.
34-
All messages in that topic will be pushed to an elasticsearch server.
35+
All messages in that topic will be pushed to an elasticsearch or opensearch server.
3536

3637
# Prerequisites to run the docker container
3738
1. You need a MQTT server to read the data from the topics.
38-
2. You need an elasticsearch v8 database to store the data inside.
39+
2. You need an elasticsearch v8 / or opensearch v2 database to store the data inside.
3940

4041
# Configuration
4142
## Container configuration
@@ -53,9 +54,9 @@ The container grab some configuration via environment variables.
5354

5455
The path and filename to the general configuration file can be set via environment variable `CONFIG_FILE`. By default, the script will use `/app/etc/mqtt2elasticsearch.json`.
5556

56-
Inside this file we need to configure the Elasticsearch and MQTT server connection parameters.
57+
Inside this file we need to configure the Elasticsearch (or Opensearch) and MQTT server connection parameters.
5758

58-
### Example
59+
### Example with Elasticsearch
5960

6061
```json
6162
{
@@ -77,6 +78,38 @@ Inside this file we need to configure the Elasticsearch and MQTT server connecti
7778
}
7879
```
7980

81+
### Example with Opensearch
82+
83+
```json
84+
{
85+
"DEBUG": true,
86+
"removeIndex": false,
87+
"opensearch": {
88+
"hosts": [
89+
{
90+
"host": "opensearch",
91+
"port": 9200
92+
}
93+
],
94+
"tls": true,
95+
"verify_certs": true,
96+
"username": "admin",
97+
"password": "admin"
98+
},
99+
"mqtt": {
100+
"client_id": "mqtt2elasticsearch",
101+
"user": "mqtt2elasticsearch",
102+
"password": "myPassword",
103+
"server": "test.mosquitto.org",
104+
"port": 1883,
105+
"tls": false,
106+
"hostname_validation": true,
107+
"protocol_version": 3
108+
}
109+
}
110+
```
111+
112+
80113
### Field description
81114

82115
| Field | Type | Description |
@@ -85,6 +118,16 @@ Inside this file we need to configure the Elasticsearch and MQTT server connecti
85118
| `removeIndex` | Boolean | If this flag is set to `true`, the script will remove the Elasticsearch index and exits. |
86119
| `elasticsearch` | Object | Contains Elasticsearch specific configuration parameters. |
87120
| `elasticsearch.cluster` | Array | Contains a list of Eleasticsearch cluster node URLs. |
121+
| `elasticsearch.api_ley` | String | Optional api\_key if Elasticsearch requires authentication. |
122+
| `opensearch` | Object | Contains Opensearch specific configuration parameters. |
123+
| `opensearch.hosts` | Array | Contains a list of Opensearch hosts objects. |
124+
| `opensearch.hosts[].host` | String | Opensearch hostname (fqdn) or IP address. |
125+
| `opensearch.hosts[].port` | String | Optional Opensearch TCP port (Default: 9200). |
126+
| `opensearch.username` | String | Optional username for authentication (Default: null). |
127+
| `opensearch.password` | String | Optional password for authentication (Default: null. |
128+
| `opensearch.tls` | Boolean | Optional if a TLS encrpted communication should be established or not (Default: false). |
129+
| `opensearch.verify_certs` | Boolean | Optional to validate the server certificate ort not (Default: false). |
130+
| `opensearch.ca_certs_path` | String | Optional path to CA certs (Default: "/etc/ssl/certs/ca-certificates.crt"). |
88131
| `mqtt` | Object | Contains MQTT specific configuration parameters. |
89132
| `mqtt.client_id` | String | The MQTT client identifier. |
90133
| `mqtt.user` | String | The username to authenticate to the MQTT server. |
@@ -96,16 +139,16 @@ Inside this file we need to configure the Elasticsearch and MQTT server connecti
96139
| `mqtt.protocol_version` | Integer | The MQTT protocol version. Can be 3 (for MQTTv311) or 5 (for MQTTv5). |
97140

98141

99-
## Elasticsearch index configuration file
142+
## Elasticsearch/Opensearch index configuration file
100143

101-
The path and filename to the Elasticsearch index configuration file can be set via environment variable `ELASTICSEARCH_MAPPING_FILE`.
144+
The path and filename to the Elasticsearch/Opensearch index configuration file can be set via environment variable `ELASTICSEARCH_MAPPING_FILE`.
102145
By default, the script will use `/app/etc/mqtt2elasticsearch-mappings.json`.
103146

104-
Inside this file we need to configure the MQTT topic and the associated Elasticsearch index with it's configuration.
147+
Inside this file we need to configure the MQTT topic and the associated Elasticsearch/Opensearch index with it's configuration.
105148

106149
### Example
107150

108-
This is minimal example. The JSON file contains the MQTT topic as **key**. Every topic contains the associated Elasticsearch index and an optional index configuration.
151+
This is minimal example. The JSON file contains the MQTT topic as **key**. Every topic contains the associated Elasticsearch/Opensearch index and an optional index configuration.
109152
You can use placeholder inside the index name. Following will be translated on the fly:
110153
- `{Y}`: the 4-digit year
111154
- `{m}`: the 2-digit month
@@ -121,7 +164,9 @@ You can use placeholder inside the index name. Following will be translated on t
121164
}
122165
```
123166

124-
A full blown example can be found here: [speedtest2mqtt-elasticsearch-mapping.json](./examples/speedtest2mqtt-elasticsearch-mapping.json).
167+
Full blown examples can be found here:
168+
- [speedtest2mqtt-elasticsearch-mapping.json](./examples/speedtest2mqtt-elasticsearch-mapping.json).
169+
- [dockerhub-stats-opensearch-mapping.json](./examples/dockerhub-stats-opensearch-mapping.json).
125170

126171

127172
### Field description
@@ -222,7 +267,7 @@ I would appreciate a small donation to support the further development of my ope
222267
223268
# License
224269
225-
Copyright (c) 2023-2024 Michael Oberdorf IT-Consulting
270+
Copyright (c) 2023-2025 Michael Oberdorf IT-Consulting
226271
227272
Permission is hereby granted, free of charge, to any person obtaining a copy
228273
of this software and associated documentation files (the "Software"), to deal
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"com/docker/hub/repositories/metrics": {
3+
"elasticIndex": "dockerhub-repositories-metrics-{Y}-{m}",
4+
"elasticBody": {
5+
"settings": {
6+
"index": {
7+
"number_of_shards": 5,
8+
"number_of_replicas": 0
9+
}
10+
},
11+
"mappings": {
12+
"properties": {
13+
"_timestamp": { "type": "date" },
14+
"user": { "type": "keyword" },
15+
"name": { "type": "keyword" },
16+
"repository_type": { "type": "keyword" },
17+
"status": { "type": "integer" },
18+
"status_description": { "type": "keyword" },
19+
"description": { "type": "text" },
20+
"is_private": { "type": "boolean" },
21+
"is_automated": { "type": "boolean" },
22+
"star_count": { "type": "integer" },
23+
"pull_count": { "type": "integer" },
24+
"last_updated": { "type": "date" },
25+
"last_modified": { "type": "date" },
26+
"date_registered": { "type": "date" },
27+
"collaborator_count": { "type": "integer" },
28+
"affiliation": { "type": "keyword" },
29+
"hub_user": { "type": "keyword" },
30+
"has_starred": { "type": "boolean" },
31+
"full_description": { "type": "text" },
32+
"permissions": { "type": "object" },
33+
"media_types": { "type": "text" },
34+
"content_types": { "type": "text" },
35+
"categories": { "type": "object" },
36+
"immutable_tags": { "type": "boolean" },
37+
"immutable_tags_rules": { "type": "keyword" },
38+
"storage_size": { "type": "integer" }
39+
}
40+
}
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)