-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathplugin.cpp
More file actions
193 lines (178 loc) · 4.4 KB
/
plugin.cpp
File metadata and controls
193 lines (178 loc) · 4.4 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
* Fledge HTTP north plugin.
*
* Copyright (c) 2020 Dianomic Systems
*
* Released under the Apache 2.0 Licence
*
* Author: Mark Riddoch
*/
#include <string>
#include <logger.h>
#include <http_north.h>
#include <plugin_api.h>
#include "version.h"
using namespace std;
#define PLUGIN_NAME "httpc"
/**
* Plugin specific default configuration
*/
static const char *default_config = QUOTE({
"plugin": {
"description": "HTTP North C Plugin, support primary and secondary destinations with failover",
"type": "string",
"default": PLUGIN_NAME,
"readonly": "true"
},
"URL": {
"description": "The URL of the HTTP Connector to send data to",
"type": "string",
"default": "http://localhost:6683/sensor-reading",
"order": "1",
"displayName": "URL",
"group" : "Connection"
},
"URL2": {
"description": "The URL of the HTTP Connector to send data to if the primary is unavailable, if empty there is no secondary",
"type": "string",
"default": "",
"order": "2",
"displayName": "Secondary URL",
"group" : "Connection"
},
"proxy": {
"description": "The name or address and port of a proxy server to use. This should be formatted as <hostname>:<port> or <address:port>",
"type": "string",
"default": "",
"order": "3",
"displayName": "Proxy",
"group" : "Connection"
},
"source": {
"description": "Defines the source of the data to be sent on the stream, this may be one of either readings, statistics or audit.",
"type": "enumeration",
"default": "readings",
"options": [ "readings", "statistics", "audit"],
"order": "4",
"displayName": "Source",
"group" : "Data"
},
"headers": {
"description": "An optional set of header fields expressed as a JSON document",
"type": "JSON",
"default": "{}",
"order": "5",
"displayName": "Headers",
"group" : "Connection"
},
"script" : {
"description" : "An optional HTTP payload translation Python script",
"type" : "script",
"default" : "",
"order" : "6",
"displayName": "Script",
"group" : "Data"
},
"retrySleepTime": {
"description": "Seconds between each retry for the communication, NOTE : the time is doubled at each attempt.",
"type": "integer",
"default": "1",
"order": "7",
"displayName" : "Sleep Time Retry",
"group" : "Tuning"
},
"maxRetry": {
"description": "Max number of retries for the communication",
"type": "integer",
"default": "3",
"order": "8",
"displayName" : "Maximum Retry",
"group" : "Tuning"
},
"HttpTimeout": {
"description": "Timeout in seconds for the HTTP operations with the HTTP Connector Relay",
"type": "integer",
"default": "10",
"order": "9",
"displayName": "Http Timeout (in seconds)",
"group" : "Tuning"
},
"verifySSL": {
"description": "Verify SSL certificate",
"type": "boolean",
"default": "False",
"order": "10",
"displayName": "Verify SSL",
"group" : "Connection"
},
"username": {
"description": "Optional username to use for HTTP basic authentication",
"type": "string",
"default": "",
"order": "11",
"displayName": "Username",
"group" : "Authentication"
},
"password": {
"description": "Password to use for HTTP basic authentication",
"type": "password",
"default": "",
"order": "12",
"displayName": "Password",
"group" : "Authentication"
}
});
/**
* The HTTP north plugin interface
*/
extern "C" {
/**
* The C API plugin information structure
*/
static PLUGIN_INFORMATION info = {
PLUGIN_NAME, // Name
VERSION, // Version
0, // Flags
PLUGIN_TYPE_NORTH, // Type
"1.0.0", // Interface version
default_config // Configuration
};
/**
* Return the information about this plugin
*/
PLUGIN_INFORMATION *plugin_info()
{
return &info;
}
/**
* Initialise the plugin with configuration.
*
* This function is called to get the plugin handle.
*/
PLUGIN_HANDLE plugin_init(ConfigCategory* config)
{
return new HttpNorth(config);
}
/**
* Send Readings data to historian server
*/
uint32_t plugin_send(const PLUGIN_HANDLE handle,
const vector<Reading *> readings)
{
HttpNorth *north = (HttpNorth *)handle;
return north->send(readings);
}
/**
* Shutdown the plugin
*
* Delete allocated data
*
* @param handle The plugin handle
*/
void plugin_shutdown(PLUGIN_HANDLE handle)
{
HttpNorth *north = (HttpNorth *)handle;
delete north;
}
// End of extern "C"
};