summaryrefslogtreecommitdiffstats
path: root/events/src/utils.py
Commit message (Collapse)AuthorAgeFilesLines
* Events: Log file not re-opened after logrotate.srijan-sivakumar2020-08-111-1/+2
| | | | | | | | | | | | | | | | | Issue: The logging is being done in the same file even after the logrotate utility has changed the file. This causes the logfile to grow indefinitely. Code Changes: Using the WatchedFileHandler class instead of FileHandler class. This watches the file it is logging into and if the file changes, it is closed and reopened using the file name. Hence after file rotate, a new file will be used for logging instead of continuing with the same old file. Fixes: #1289 Change-Id: I773d04f17613a03709cb682692efb39fd8e664e2 Signed-off-by: srijan-sivakumar <ssivakum@redhat.com>
* eventsapi: Fix Python3 compatibility issuesAravinda VK2019-02-251-8/+11
| | | | | | | | | | | - Fixed Relative import and non-package import related issues. - socketserver import issues fix - Renamed installed directory name to `gfevents` from `events`(To avoid any issues with other global libs) Fixes: bz#1679406 Change-Id: I3dc38bc92b23387a6dfbcc0ab8283178235bf756 Signed-off-by: Aravinda VK <avishwan@redhat.com>
* events: python2 to python3 compatKotresh HR2018-10-081-2/+2
| | | | | | | | | | 1. Fix imports 2. Use universal_newlines flag in Popen 3. encode msg used in 'sendto' Updates: #411 Change-Id: Ieacdc2ba86953ff3a2e9d9b9a97157e8e0e36836 Signed-off-by: Kotresh HR <khiremat@redhat.com>
* All: run codespell on the code and fix issues.Yaniv Kaul2018-07-221-2/+2
| | | | | | | | | | | | Please review, it's not always just the comments that were fixed. I've had to revert of course all calls to creat() that were changed to create() ... Only compile-tested! Change-Id: I7d02e82d9766e272a7fd9cc68e51901d69e5aab5 updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
* core/various: python3 compat, prepare for python2 -> python3Kaleb S. KEITHLEY2018-06-041-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | see https://review.gluster.org/#/c/19788/, https://review.gluster.org/#/c/19871/, and https://review.gluster.org/#/c/19952/ This patch adds version agnostic imports for urllib, cpickle, socketserver, _thread, queue, etc., suggested by Aravinda in https://review.gluster.org/#/c/19767/1 Note: Fedora packaging guidelines require explicit shebangs, so popular practices like #!/usr/bin/env python and #!/usr/bin/python are not allowed; they must be #!/usr/bin/python2 or #!/usr/bin/python3 Note: Selected small fixes from 2to3 utility. Specifically apply, basestring, funcattrs, idioms, numliterals, set_literal, types, urllib, and zip have already been applied. Note: these 2to3 fixes report no changes are necessary: exec, execfile, exitfunc, filter, getcwdu, intern, itertools, metaclass, methodattrs, ne, next, nonzero, operator, paren, raw_input, reduce, reload, renames, repr, standarderror, sys_exc, throw, tuple_params, xreadlines. Change-Id: I8d393064a1837874d8b4bc87c8ce05c679664642 updates: #411 Signed-off-by: Kaleb S. KEITHLEY <kkeithle@redhat.com>
* eventsapi: Handle Unicode string during signingAravinda VK2018-04-201-1/+1
| | | | | | | | | | | Python 2.7 HMAC does not support Unicode strings. Secret is read from file so it is possible that glustereventsd reads the content as Unicode. This patch converts the secret to `str` type before generating HMAC signature. Fixes: bz#1568820 Change-Id: I7daa64499ac4ca02544405af26ac8af4b6b0bd95 Signed-off-by: Aravinda VK <avishwan@redhat.com>
* eventsapi: JWT signing without external dependencyAravinda VK2017-12-281-3/+17
| | | | | | | | | Added support for JWT signing without using python-jwt since it is not available in all the distributions. BUG: 1529463 Change-Id: I95699055442fbf9da15249f5defe8a8b287010f1 Signed-off-by: Aravinda VK <avishwan@redhat.com>
* eventsapi: HTTPS support for WebhooksAravinda VK2017-10-311-21/+73
| | | | | | | | | | | | | | | | | First it tries to call URL with verify=True without specifying the cert path, it succeeds if a webhook is HTTP or HTTPS with CA trusted certificates(for example https://github..). If above call fails with SSL error then it tries to get the server certificate and calls URL again. If call fails with SSL error even after using the certificate, then verification will be disabled and logged in the log file. All other errors will be catched and logged as usual. BUG: 1506903 Change-Id: I86a3390ed48b75dffdc7848022af23a1e1d7f076 Signed-off-by: Aravinda VK <avishwan@redhat.com>
* eventsapi: Add JWT signing supportAravinda VK2017-10-131-9/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | New argument added to accept secret to generate JWT token. This patch does not affect the backward compatibility. Usage: gluster-eventsapi webhook-add <url> [-t <TOKEN>] \ [-s SECRET] With `--token` argument, Token header will be added as is. Authorization: Bearer <TOKEN> In case of shared secret, Gluster will generate JWT token using the secret and then add it to Authorization header. Authorization: Bearer <GENERATED_TOKEN> Secret/Token can be updated using `webhook-mod` command. Generated token will include the following payload, { "iss": "gluster", "exp": EXPIRY_TIME, "sub": EVENT_TYPE, "iat": EVENT_TIME } Where: iss - Issuer, exp - Expiry Time, sub - Event Type used as Subject, iat - Event Time used as Issue Time BUG: 1496363 Change-Id: Ib6b6fab23fb212d7f5e9bbc9e1416a9e9813ab1b Signed-off-by: Aravinda VK <avishwan@redhat.com>
* eventsapi: Log all published events and provide option to disable loggingAravinda VK2016-12-081-3/+12
| | | | | | | | | | | | | | | | | | Log every published event in /var/log/glusterfs/events.log, Disable logging using, gluster-eventsapi config-set disable-events-log true Also changed "log_level" config name to "log-level" Change-Id: Ib354be0c4ca999d1ccd01b810d6cd96ebc72bcd4 BUG: 1386200 Signed-off-by: Aravinda VK <avishwan@redhat.com> Reviewed-on: http://review.gluster.org/15674 Reviewed-by: Prashanth Pai <ppai@redhat.com> Smoke: Gluster Build System <jenkins@build.gluster.org> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
* eventsapi: Push Messages to Webhooks in parallelAravinda VK2016-12-021-5/+65
| | | | | | | | | | | | | | | | | | With this patch, glustereventsd will maintain one thread per webhook. If a webhook is slow, then all the events to that worker will be delayed but it will not affect the other webhooks. Note: Webhook in transit may get missed if glustereventsd reloads due to new Webhook addition or due configuration changes. BUG: 1357754 Change-Id: I2d11e01c7ac434355bc356ff75396252f51b339b Signed-off-by: Aravinda VK <avishwan@redhat.com> Reviewed-on: http://review.gluster.org/15966 Smoke: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: Prashanth Pai <ppai@redhat.com> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
* eventsapi: Auto reload Webhooks data when modifiedAravinda VK2016-11-171-1/+20
| | | | | | | | | | | | | | | | | | | glustereventsd depends on reload signal to reload the Webhooks configurations. But if reload signal missed, no events will be sent to newly added Webhook. Added auto reload based on webhooks file mtime. Before pushing events to Webhooks, reloads webhooks configurations if previously recorded mtime is different than current mtime. BUG: 1388862 Change-Id: I83a41d6a52d8fa1d70e88294298f4a5c396d4158 Signed-off-by: Aravinda VK <avishwan@redhat.com> Reviewed-on: http://review.gluster.org/15731 Reviewed-by: Prashanth Pai <ppai@redhat.com> Smoke: Gluster Build System <jenkins@build.gluster.org> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
* eventsapi: Auto convert Boolean and Int attributesAravinda VK2016-10-191-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before publishing in JSON format, automatically convert the attribute to "bool" or "int" if configured. For example, instead of sending force="1", convert to bool and send as force=True { "event": "VOLUME_START", "name" : "gv1", "force": "1" } Convert to, { "event": "VOLUME_START", "name" : "gv1", "force": true } BUG: 1379328 Change-Id: Iabc51fd61abc267a7c8dcf0aeac6b3c722d89649 Signed-off-by: Aravinda VK <avishwan@redhat.com> Reviewed-on: http://review.gluster.org/15574 NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> CentOS-regression: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: Prashanth Pai <ppai@redhat.com> Smoke: Gluster Build System <jenkins@build.gluster.org>
* eventsapi: Add conditional import for requests libraryAravinda VK2016-09-091-1/+3
| | | | | | | | | | | | | | | | | | requests lib is used only during publishing event. gf_event python imports utils.py, and indirectly imports requests lib even though it is not required while sending event to eventsd. Moved "import requests" inside the "plugin_webhook" function. BUG: 1374587 Change-Id: Ie3c8088b43d4d7952d01352731999bf8519c73c4 Signed-off-by: Aravinda VK <avishwan@redhat.com> Reviewed-on: http://review.gluster.org/15439 Reviewed-by: Prashanth Pai <ppai@redhat.com> Smoke: Gluster Build System <jenkins@build.gluster.org> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> Reviewed-by: Kotresh HR <khiremat@redhat.com> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
* eventsapi: Add Init scripts for different distributionsAravinda VK2016-09-091-0/+77
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Added init scripts for - SysvInit(CentOS 6 or Red Hat 6) - rc.d (FreeBSD) Most of the latest distributions are using systemd. Support to be added for other distributions which are not using systemd. Removed systemctl wrapper functions(start/stop/status) from gluster-eventsapi CLI(peer_eventsapi.py). Status and Reload re-implemented using pid file check. Added pid file support for glustereventsd. Following dependencies removed python-flask - Only used for example dashboard. User can install if required. python-fasteners - Not available for EPEL 6, added custom code using fcntl as replacement. BUG: 1365395 Change-Id: I26792eae9b11e93304f70b3997cd7d8d03b067f4 Signed-off-by: Aravinda VK <avishwan@redhat.com> Reviewed-on: http://review.gluster.org/15367 Smoke: Gluster Build System <jenkins@build.gluster.org> CentOS-regression: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: Niels de Vos <ndevos@redhat.com> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
* eventsapi: Add support for Client side EventsAravinda VK2016-08-301-4/+24
| | | | | | | | | | | | | | | | | | | | | | | | | Client side gf_event uses ctx->cmd_args.volfile_server to push notifications to the eventsd. Socket server changed from Unix domain socket to UDP to support external events. Following to be addressed in different patch - Port used for eventsd is 24009. Make it configurable Already configurable in Server side. Configurable in gf_event API is required. - Auth Token yet to be added as discussed in https://www.gluster.org/pipermail/gluster-devel/2016-August/050324.html Change-Id: I159acf80b681d10b82d52cfb3ffdf85cb896542d BUG: 1367774 Signed-off-by: Aravinda VK <avishwan@redhat.com> Reviewed-on: http://review.gluster.org/15189 Smoke: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: Prashanth Pai <ppai@redhat.com> Reviewed-by: Atin Mukherjee <amukherj@redhat.com> CentOS-regression: Gluster Build System <jenkins@build.gluster.org> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
* eventsapi: Gluster Eventing Feature implementationAravinda VK2016-07-181-0/+150
[Depends on http://review.gluster.org/14627] Design is available in `glusterfs-specs`, A change from the design is support of webhook instead of Websockets as discussed in the design http://review.gluster.org/13115 Since Websocket support depends on REST APIs, I will add Websocket support once REST APIs patch gets merged Usage: Run following command to start/stop Eventsapi server in all Peers, which will collect the notifications from any Gluster daemon and emits to configured client. gluster-eventsapi start|stop|restart|reload Status of running services can be checked using, gluster-eventsapi status Events listener is a HTTP(S) server which listens to events emited by the Gluster. Create a HTTP Server to listen on POST and register that URL using, gluster-eventsapi webhook-add <URL> [--bearer-token <TOKEN>] For example, if HTTP Server running in `http://192.168.122.188:9000` then add that URL using, gluster-eventsapi webhook-add http://192.168.122.188:9000 If it expects a Token then specify it using `--bearer-token` or `-t` We can also test Webhook if all peer nodes can send message or not using, gluster-eventsapi webhook-test <URL> [--bearer-token <TOKEN>] Configurations can be viewed/updated using, gluster-eventsapi config-get [--name] gluster-eventsapi config-set <NAME> <VALUE> gluster-eventsapi config-reset <NAME|all> If any one peer node was down during config-set/reset or webhook modifications, Run sync command from good node when a peer node comes back. Automatic update is not yet implemented. gluster-eventsapi sync Basic Events Client(HTTP Server) is included with the code, Start running the client with required port and start listening to the events. /usr/share/glusterfs/scripts/eventsdash.py --port 8080 Default port is 9000, if no port is specified, once it started running then configure gluster-eventsapi to send events to that client. Eventsapi Client can be outside of the Cluster, it can be run event on Windows. But only requirement is the client URL should be accessible by all peer nodes.(Or ngrok(https://ngrok.com) like tools can be used) Events implemented with this patch, - Volume Create - Volume Start - Volume Stop - Volume Delete - Peer Attach - Peer Detach It is easy to add/support more events, since it touches Gluster cmd code and to avoid merge conflicts I will add support for more events once this patch merges. BUG: 1334044 Change-Id: I316827ac9dd1443454df7deffe4f54835f7f6a08 Signed-off-by: Aravinda VK <avishwan@redhat.com> Reviewed-on: http://review.gluster.org/14248 Smoke: Gluster Build System <jenkins@build.gluster.org> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> CentOS-regression: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: Jeff Darcy <jdarcy@redhat.com>