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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
|
<!-- ##### SECTION Title ##### -->
prelude-client
<!-- ##### SECTION Short_Description ##### -->
Creating a Prelude Client
<!-- ##### SECTION Long_Description ##### -->
<para>
In order to send or to read data from a Prelude collector (prelude-manager),
you will need to create a #prelude_client_t object. This object will be necessary
for most of the work you are going to do with prelude.
</para>
<title>Creating the client</title>
<para>
<programlisting>
int ret;
prelude_client_t *client;
ret = prelude_client_new(&client, "my-analyzer");
if ( ! client ) {
prelude_perror(ret, "Unable to create a prelude client object");
return -1;
}
</programlisting>
This will create a new client object, whose default profile is my-analyzer.
This default profile might be overriden using the --prelude --profile profile_name option on your
command line as parsed by prelude_init().
</para>
<para>
Additionally, prelude specific option might be overriden using a Prelude specific configuration file,
like the template file created within each profile, or a configuration file specified using
prelude_client_set_config_filename() before prelude_client_start() is called.
</para>
<para>
The default required permission for the created client are set to PRELUDE_CONNECTION_PERMISSION_IDMEF_WRITE
and PRELUDE_CONNECTION_PERMISSION_ADMIN_READ, which mean the client will reject any certificate where
permission are set to anything less than this. You can change the default required permission using the
prelude_client_set_required_permission() function.
</para>
<para>
As an example, if you want to create a client that will read alert from a Manager, and accept administrative
option request you should use:
<programlisting>
prelude_client_set_required_permission(client, PRELUDE_CONNECTION_PERMISSION_IDMEF_READ|PRELUDE_CONNECTION_PERMISSION_ADMIN_WRITE);
</programlisting>
</para>
<para>
Once the client is created and you have everything setup, you will need to start your client.
The prelude_client_start() function is responsible for this, and will trigger the connection to
the configured manager, and send the initial client heartbeat.
</para>
<programlisting>
ret = prelude_client_start(client);
if ( ret < 0 ) {
prelude_log(ret, "Unable to start prelude client");
return -1;
}
</programlisting>
<para>
Additionally, it is possible to set additional client flags, however, you should be careful
since some of theses flags (marked asynchronous) will result in creating an internal thread,
which should only be done after an eventual fork of the program since threads are not copied
accross a fork call.
</para>
<para>
The prelude library will also register an internal timer in order to send heartbeat message at
the defined interval. Timer registered by the library itself or by the program will either be called
automatically if the #PRELUDE_CLIENT_FLAGS_ASYNC_TIMER flags is set, otherwise, the program is responsible
for calling the prelude_timer_wake_up() function every second from it's main loop, in order to check the
registered timer.
<itemizedlist>
<listitem>#PRELUDE_CLIENT_FLAGS_CONNECT - Used for a client to connect to a manager (this is the default).</listitem>
<listitem>#PRELUDE_CLIENT_FLAGS_HEARTBEAT - Used for client to send heartbeat (this is the default).</listitem>
<listitem>#PRELUDE_CLIENT_FLAGS_ASYNC_SEND - Used if you want message to be sent asynchronously.</listitem>
<listitem>#PRELUDE_CLIENT_FLAGS_ASYNC_TIMER - Used if you want timer to be automatically called from the asynchronous thread.</listitem>
<listitem>See #prelude_client_flags_t for a list of available flags.</listitem>
</itemizedlist>
<programlisting>
ret = prelude_client_set_flags(client, PRELUDE_CLIENT_FLAGS_ASYNC_SEND|PRELUDE_CLIENT_FLAGS_ASYNC_TIMER);
if ( ret < 0 ) {
fprintf(stderr, "Unable to set asynchronous send and timer.\n");
return -1;
}
</programlisting>
</para>
<title>Sending IDMEF message</title>
<para>
For documentation on how to create IDMEF message, please see #idmef_message_t
or #idmef_path_t.
</para>
<para>
Once you created and IDMEF message, you should use the prelude_client_send_idmef() function
in order to send it to the collector you are connected to.
<informalexample><programlisting>
prelude_client_send_idmef(client, idmef);
</programlisting></informalexample>
</para>
<title>Destroying the client</title>
<para>
In case the analyzer you are developing is not a persistant analyzer (meaning an
analyzer that is not supposed to exit), it is important that you call the prelude_client_destroy()
function prior to exiting. This function have the side effect of sending an heartbeat to the remote
manager, as well as an information regarding the analyzer state.
</para>
<para>
This state information is important since an analyzer not reporting a successful exit status,
or an analyzer which stop sending heartbeat at all will be reported as having a problem.
<itemizedlist>
<listitem>PRELUDE_CLIENT_STATUS_EXIT_SUCCESS - Exiting the sensor is the expected behavior.</listitem>
<listitem>PRELUDE_CLIENT_STATUS_EXIT_FAILED - There is something wrong going on, notice the security analyst.</listitem>
</itemizedlist>
<informalexample><programlisting>
prelude_client_destroy(client, PRELUDE_CLIENT_STATUS_EXIT_SUCCESS);
</programlisting></informalexample>
As a side note, please remember that a persistant sensor should never use this function
(except maybe if it is working in batch mode), unless it want to report the
PRELUDE_CLIENT_STATUS_EXIT_FAILED exit status. This is also the case if your persistant sensor
is interrupted by a signal.
</para>
<!-- ##### SECTION See_Also ##### -->
<para>
#idmef_message_t
#idmef_path_t
</para>
<!-- ##### SECTION Stability_Level ##### -->
<!-- ##### ENUM prelude_client_exit_status_t ##### -->
<para>
</para>
@PRELUDE_CLIENT_EXIT_STATUS_SUCCESS:
@PRELUDE_CLIENT_EXIT_STATUS_FAILURE:
<!-- ##### ENUM prelude_client_flags_t ##### -->
<para>
</para>
@PRELUDE_CLIENT_FLAGS_ASYNC_SEND:
@PRELUDE_CLIENT_FLAGS_ASYNC_TIMER:
@PRELUDE_CLIENT_FLAGS_HEARTBEAT:
@PRELUDE_CLIENT_FLAGS_CONNECT:
<!-- ##### TYPEDEF prelude_client_t ##### -->
<para>
</para>
<!-- ##### FUNCTION prelude_client_get_unique_ident ##### -->
<para>
</para>
@client:
@Returns:
<!-- ##### FUNCTION prelude_client_set_connection_pool ##### -->
<para>
</para>
@client:
@pool:
<!-- ##### FUNCTION prelude_client_get_connection_pool ##### -->
<para>
</para>
@client:
@Returns:
<!-- ##### FUNCTION prelude_client_start ##### -->
<para>
</para>
@client:
@Returns:
<!-- ##### FUNCTION prelude_client_init ##### -->
<para>
</para>
@client:
@Returns:
<!-- ##### FUNCTION prelude_client_new ##### -->
<para>
</para>
@client:
@profile:
@Returns:
<!-- # Unused Parameters # -->
@config:
@capability:
<!-- ##### FUNCTION prelude_client_get_analyzer ##### -->
<para>
</para>
@client:
@Returns:
<!-- ##### FUNCTION prelude_client_get_flags ##### -->
<para>
</para>
@client:
@Returns:
<!-- ##### FUNCTION prelude_client_set_required_permission ##### -->
<para>
</para>
@client:
@permission:
<!-- ##### FUNCTION prelude_client_get_required_permission ##### -->
<para>
</para>
@client:
@Returns:
<!-- ##### FUNCTION prelude_client_send_msg ##### -->
<para>
</para>
@client:
@msg:
<!-- ##### FUNCTION prelude_client_set_heartbeat_cb ##### -->
<para>
</para>
@client:
@cb:
<!-- ##### FUNCTION prelude_client_send_idmef ##### -->
<para>
</para>
@client:
@msg:
<!-- ##### FUNCTION prelude_client_destroy ##### -->
<para>
</para>
@client:
@status:
<!-- ##### FUNCTION prelude_client_set_flags ##### -->
<para>
</para>
@client:
@flags:
@Returns:
<!-- ##### FUNCTION prelude_client_set_config_filename ##### -->
<para>
</para>
@client:
@filename:
@Returns:
<!-- ##### FUNCTION prelude_client_get_config_filename ##### -->
<para>
</para>
@client:
@Returns:
<!-- ##### FUNCTION prelude_client_print_setup_error ##### -->
<para>
</para>
@client:
<!-- ##### FUNCTION prelude_client_get_setup_error ##### -->
<para>
</para>
@client:
@Returns:
<!-- ##### FUNCTION prelude_client_is_setup_needed ##### -->
<para>
</para>
@error:
@Returns:
<!-- ##### FUNCTION prelude_client_get_profile ##### -->
<para>
</para>
@client:
@Returns:
<!-- ##### FUNCTION prelude_client_new_msgbuf ##### -->
<para>
</para>
@client:
@msgbuf:
@Returns:
<!-- ##### FUNCTION prelude_client_handle_msg_default ##### -->
<para>
</para>
@client:
@msg:
@msgbuf:
@Returns:
|