pycti 5.12.20__py3-none-any.whl → 5.12.21__py3-none-any.whl

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.

Potentially problematic release.


This version of pycti might be problematic. Click here for more details.

pycti/__init__.py CHANGED
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
- __version__ = "5.12.20"
2
+ __version__ = "5.12.21"
3
3
 
4
4
  from .api.opencti_api_client import OpenCTIApiClient
5
5
  from .api.opencti_api_connector import OpenCTIApiConnector
@@ -11,7 +11,6 @@ import sys
11
11
  import tempfile
12
12
  import threading
13
13
  import time
14
- import traceback
15
14
  import uuid
16
15
  from queue import Queue
17
16
  from typing import Callable, Dict, List, Optional, Union
@@ -30,7 +29,6 @@ FALSY: List[str] = ["no", "false", "False"]
30
29
 
31
30
 
32
31
  def killProgramHook(etype, value, tb):
33
- traceback.print_exception(etype, value, tb)
34
32
  os.kill(os.getpid(), signal.SIGTERM)
35
33
 
36
34
 
@@ -290,8 +288,10 @@ class ListenQueue(threading.Thread):
290
288
  )
291
289
 
292
290
  def run(self) -> None:
291
+ self.helper.connector_logger.info("Starting ListenQueue thread")
293
292
  while not self.exit_event.is_set():
294
293
  try:
294
+ self.helper.connector_logger.info("ListenQueue connecting to rabbitMq.")
295
295
  # Connect the broker
296
296
  self.pika_credentials = pika.PlainCredentials(self.user, self.password)
297
297
  self.pika_parameters = pika.ConnectionParameters(
@@ -308,28 +308,32 @@ class ListenQueue(threading.Thread):
308
308
  self.pika_connection = pika.BlockingConnection(self.pika_parameters)
309
309
  self.channel = self.pika_connection.channel()
310
310
  try:
311
+ # confirm_delivery is only for cluster mode rabbitMQ
312
+ # when not in cluster mode this line raise an exception
311
313
  self.channel.confirm_delivery()
312
314
  except Exception as err: # pylint: disable=broad-except
313
- self.helper.connector_logger.warning(str(err))
315
+ self.helper.connector_logger.debug(str(err))
314
316
  self.channel.basic_qos(prefetch_count=1)
315
317
  assert self.channel is not None
316
318
  self.channel.basic_consume(
317
319
  queue=self.queue_name, on_message_callback=self._process_message
318
320
  )
319
321
  self.channel.start_consuming()
320
- except (KeyboardInterrupt, SystemExit):
321
- self.channel.stop_consuming()
322
- self.pika_connection.close()
323
- self.helper.connector_logger.info("Connector stop")
324
- sys.exit(0)
325
322
  except Exception as err: # pylint: disable=broad-except
326
- self.pika_connection.close()
323
+ try:
324
+ self.pika_connection.close()
325
+ except Exception as errInException:
326
+ self.helper.connector_logger.debug(
327
+ type(errInException).__name__, {"reason": str(errInException)}
328
+ )
327
329
  self.helper.connector_logger.error(
328
330
  type(err).__name__, {"reason": str(err)}
329
331
  )
330
- sys.exit(1)
332
+ # Wait some time and then retry ListenQueue again.
333
+ time.sleep(10)
331
334
 
332
335
  def stop(self):
336
+ self.helper.connector_logger.info("Preparing ListenQueue for clean shutdown")
333
337
  self.exit_event.set()
334
338
  self.pika_connection.close()
335
339
  if self.thread:
@@ -353,6 +357,7 @@ class PingAlive(threading.Thread):
353
357
  def ping(self) -> None:
354
358
  while not self.exit_event.is_set():
355
359
  try:
360
+ self.connector_logger.debug("PingAlive running.")
356
361
  initial_state = self.get_state()
357
362
  result = self.api.connector.ping(self.connector_id, initial_state)
358
363
  remote_state = (
@@ -378,11 +383,11 @@ class PingAlive(threading.Thread):
378
383
  self.exit_event.wait(40)
379
384
 
380
385
  def run(self) -> None:
381
- self.connector_logger.info("Starting ping alive thread")
386
+ self.connector_logger.info("Starting PingAlive thread")
382
387
  self.ping()
383
388
 
384
389
  def stop(self) -> None:
385
- self.connector_logger.info("Preparing for clean shutdown")
390
+ self.connector_logger.info("Preparing PingAlive for clean shutdown")
386
391
  self.exit_event.set()
387
392
 
388
393
 
@@ -395,10 +400,11 @@ class StreamAlive(threading.Thread):
395
400
 
396
401
  def run(self) -> None:
397
402
  try:
398
- self.helper.connector_logger.info("Starting stream alive thread")
403
+ self.helper.connector_logger.info("Starting StreamAlive thread")
399
404
  time_since_last_heartbeat = 0
400
405
  while not self.exit_event.is_set():
401
406
  time.sleep(5)
407
+ self.helper.connector_logger.debug("StreamAlive running")
402
408
  try:
403
409
  self.q.get(block=False)
404
410
  time_since_last_heartbeat = 0
@@ -409,12 +415,18 @@ class StreamAlive(threading.Thread):
409
415
  "Time since last heartbeat exceeded 45s, stopping the connector"
410
416
  )
411
417
  break
418
+ self.helper.connector_logger.info(
419
+ "Exit event in StreamAlive loop, stopping process."
420
+ )
412
421
  sys.excepthook(*sys.exc_info())
413
- except:
422
+ except Exception as ex:
423
+ self.helper.connector_logger.error(
424
+ "Error in StreamAlive loop, stopping process.", {"reason": str(ex)}
425
+ )
414
426
  sys.excepthook(*sys.exc_info())
415
427
 
416
428
  def stop(self) -> None:
417
- self.helper.connector_logger.info("Preparing for clean shutdown")
429
+ self.helper.connector_logger.info("Preparing StreamAlive for clean shutdown")
418
430
  self.exit_event.set()
419
431
 
420
432
 
@@ -449,6 +461,7 @@ class ListenStream(threading.Thread):
449
461
 
450
462
  def run(self) -> None: # pylint: disable=too-many-branches
451
463
  try:
464
+ self.helper.connector_logger.info("Starting ListenStream thread")
452
465
  current_state = self.helper.get_state()
453
466
  start_from = self.start_timestamp
454
467
  recover_until = self.recover_iso_date
@@ -545,10 +558,14 @@ class ListenStream(threading.Thread):
545
558
  self.exit = True
546
559
  state["start_from"] = str(msg.id)
547
560
  self.helper.set_state(state)
548
- except:
561
+ except Exception as ex:
562
+ self.helper.connector_logger.error(
563
+ "Error in ListenStream loop, exit.", {"reason": str(ex)}
564
+ )
549
565
  sys.excepthook(*sys.exc_info())
550
566
 
551
567
  def stop(self):
568
+ self.helper.connector_logger.info("Preparing ListenStream for clean shutdown")
552
569
  self.exit_event.set()
553
570
 
554
571
 
@@ -735,6 +752,7 @@ class OpenCTIConnectorHelper: # pylint: disable=too-many-public-methods
735
752
  self.listen_queue = None
736
753
 
737
754
  def stop(self) -> None:
755
+ self.connector_logger.info("Preparing connector for clean shutdown")
738
756
  if self.listen_queue:
739
757
  self.listen_queue.stop()
740
758
  # if self.listen_stream:
@@ -59,6 +59,3 @@ def logger(level, json_logging=True):
59
59
  )
60
60
 
61
61
  return AppLogger
62
-
63
-
64
- test_logger = logger("INFO")("test")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycti
3
- Version: 5.12.20
3
+ Version: 5.12.21
4
4
  Summary: Python API client for OpenCTI.
5
5
  Home-page: https://github.com/OpenCTI-Platform/client-python
6
6
  Author: Filigran
@@ -1,4 +1,4 @@
1
- pycti/__init__.py,sha256=pLd6WGQzxBONIs69NPo8dVZ2_9w8XEsBHFAYD8bjMYg,4693
1
+ pycti/__init__.py,sha256=5rJrcMDJuOyvnvrA5rhaRrCOPQAkNWdbnPq6dSB01Y8,4693
2
2
  pycti/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  pycti/api/opencti_api_client.py,sha256=7N2dUApNQlZpd8iBYS16N-G5YHbc_LOVIGKzKYZ9PPk,27965
4
4
  pycti/api/opencti_api_connector.py,sha256=fYF0Jy9KIMFNt1RC_A1rpWomVJ-oj5HiSsBem4W0J5U,3549
@@ -6,7 +6,7 @@ pycti/api/opencti_api_playbook.py,sha256=Wcf-G__IHmR7LwtUFVUVx4Skg9e2mcb89n_HyfW
6
6
  pycti/api/opencti_api_work.py,sha256=ow30gswv4k5zLlZGlvLAn47ZM07RLsYvEV-KwtwedQg,7109
7
7
  pycti/connector/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  pycti/connector/opencti_connector.py,sha256=0vrZ8Y8ecbxegAP1YhpX6ybOZahYjjOkcId51D1oBi4,2449
9
- pycti/connector/opencti_connector_helper.py,sha256=mcIr5QnX_6ANVUqz5nQFmMeLoE08zkljO3i3Oa13psY,48874
9
+ pycti/connector/opencti_connector_helper.py,sha256=ms-XxTIX4K35Oc9PHfgBFMeHOFHt-KGDffuGurUQF2M,50121
10
10
  pycti/connector/opencti_metric_handler.py,sha256=4jXHeJflomtHjuQ_YU0b36TG7o26vOWbY_jvU8Ezobs,3725
11
11
  pycti/entities/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
12
  pycti/entities/opencti_attack_pattern.py,sha256=THsn1IVJwtKVdVaX5WeUyjxuG5vZV6Qd_aY6po73Lqk,22523
@@ -56,13 +56,13 @@ pycti/entities/opencti_vocabulary.py,sha256=6JfOByggvSxvkfIXk1b60T7fyWOhxZ6YFkGb
56
56
  pycti/entities/opencti_vulnerability.py,sha256=UF9gYCsPbj8w79v3xTku3vjThlggC3xbSs9JK8ns7BQ,18393
57
57
  pycti/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
58
58
  pycti/utils/constants.py,sha256=g53_tdaq_akCm-ZC0TI2Y5V1yE7ejgB6E-rCDZ86bag,7914
59
- pycti/utils/opencti_logger.py,sha256=9Nor76Hb4uADs7COxEvy9lfCZpBvBl-Y2RKw0yvgxcI,2238
59
+ pycti/utils/opencti_logger.py,sha256=0dvB75V0SuPFGxL539dAQrxTt1N5Acx0A3Ogwl5WMJ8,2199
60
60
  pycti/utils/opencti_stix2.py,sha256=udN8G3Q5NtrpbCS6wn6tsDbF4wh9pdP9tSSTUpWy-3k,109517
61
61
  pycti/utils/opencti_stix2_splitter.py,sha256=Ht9Mp-W3gbwxIKEr7i_5NYpcDr3TA2gYdC4TzOz0G4c,4496
62
62
  pycti/utils/opencti_stix2_update.py,sha256=rU7j3kAN3hD5LNnCQki8sYVMqJ86cXIOPAizesN7bQk,14426
63
63
  pycti/utils/opencti_stix2_utils.py,sha256=XaDLRN9BE-n8chO9OEsCMoonAuoMjoGS_OSJyrxVXDY,3677
64
- pycti-5.12.20.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
65
- pycti-5.12.20.dist-info/METADATA,sha256=w0iYjLtMeCNe-sce7EM4dUB7ePe-vBzBa0jDJqBKdhQ,5298
66
- pycti-5.12.20.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
67
- pycti-5.12.20.dist-info/top_level.txt,sha256=cqEpxitAhHP4VgSA6xmrak6Yk9MeBkwoMTB6k7d2ZnE,6
68
- pycti-5.12.20.dist-info/RECORD,,
64
+ pycti-5.12.21.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
65
+ pycti-5.12.21.dist-info/METADATA,sha256=bQT6-bZn33tFCCr7cpU5dRP2tBHqpRJBTC_0eeKP4do,5298
66
+ pycti-5.12.21.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
67
+ pycti-5.12.21.dist-info/top_level.txt,sha256=cqEpxitAhHP4VgSA6xmrak6Yk9MeBkwoMTB6k7d2ZnE,6
68
+ pycti-5.12.21.dist-info/RECORD,,