Error while context gets saved
Added by Henry Depu over 8 years ago
Hi,
when I exit the prelude-correlator 1.2.6, I get the following exception:
preludecorrelator.main (pid:26924) INFO: caught signal 2 Traceback (most recent call last): File "/usr/local/bin/prelude-correlator", line 9, in <module> load_entry_point('prelude-correlator==1.2.6', 'console_scripts', 'prelude-correlator')() File "/usr/local/lib/python2.7/dist-packages/preludecorrelator/main.py", line 251, in main runCorrelator() File "/usr/local/lib/python2.7/dist-packages/preludecorrelator/main.py", line 246, in runCorrelator context.save() File "/usr/local/lib/python2.7/dist-packages/preludecorrelator/context.py", line 362, in save pickle.dump(_CONTEXT_TABLE, fd) File "/usr/lib/python2.7/pickle.py", line 1370, in dump Pickler(file, protocol).dump(obj) File "/usr/lib/python2.7/pickle.py", line 224, in dump self.save(obj) File "/usr/lib/python2.7/pickle.py", line 286, in save f(self, obj) # Call unbound method with explicit self File "/usr/lib/python2.7/pickle.py", line 649, in save_dict self._batch_setitems(obj.iteritems()) File "/usr/lib/python2.7/pickle.py", line 663, in _batch_setitems save(v) File "/usr/lib/python2.7/pickle.py", line 286, in save f(self, obj) # Call unbound method with explicit self File "/usr/lib/python2.7/pickle.py", line 600, in save_list self._batch_appends(iter(obj)) File "/usr/lib/python2.7/pickle.py", line 615, in _batch_appends save(x) File "/usr/lib/python2.7/pickle.py", line 306, in save rv = reduce(self.proto) File "/usr/lib/python2.7/copy_reg.py", line 84, in _reduce_ex dict = getstate() File "/usr/local/lib/python2.7/dist-packages/preludecorrelator/idmef.py", line 46, in __getstate__ del(odict["this"]) KeyError: 'this'
When I delete "del(odict["this"])" in idmef.py, I get the following exception:
preludecorrelator.main (pid:26985) INFO: caught signal 2 Traceback (most recent call last): File "/usr/local/bin/prelude-correlator", line 9, in <module> load_entry_point('prelude-correlator==1.2.6', 'console_scripts', 'prelude-correlator')() File "/usr/local/lib/python2.7/dist-packages/preludecorrelator/main.py", line 251, in main runCorrelator() File "/usr/local/lib/python2.7/dist-packages/preludecorrelator/main.py", line 246, in runCorrelator context.save() File "/usr/local/lib/python2.7/dist-packages/preludecorrelator/context.py", line 362, in save pickle.dump(_CONTEXT_TABLE, fd) File "/usr/lib/python2.7/pickle.py", line 1370, in dump Pickler(file, protocol).dump(obj) File "/usr/lib/python2.7/pickle.py", line 224, in dump self.save(obj) File "/usr/lib/python2.7/pickle.py", line 286, in save f(self, obj) # Call unbound method with explicit self File "/usr/lib/python2.7/pickle.py", line 649, in save_dict self._batch_setitems(obj.iteritems()) File "/usr/lib/python2.7/pickle.py", line 663, in _batch_setitems save(v) File "/usr/lib/python2.7/pickle.py", line 286, in save f(self, obj) # Call unbound method with explicit self File "/usr/lib/python2.7/pickle.py", line 600, in save_list self._batch_appends(iter(obj)) File "/usr/lib/python2.7/pickle.py", line 615, in _batch_appends save(x) File "/usr/lib/python2.7/pickle.py", line 331, in save self.save_reduce(obj=obj, *rv) File "/usr/lib/python2.7/pickle.py", line 401, in save_reduce save(args) File "/usr/lib/python2.7/pickle.py", line 286, in save f(self, obj) # Call unbound method with explicit self File "/usr/lib/python2.7/pickle.py", line 562, in save_tuple save(element) File "/usr/lib/python2.7/pickle.py", line 306, in save rv = reduce(self.proto) File "/usr/lib/python2.7/copy_reg.py", line 70, in _reduce_ex raise TypeError, "can't pickle %s objects" % base.__name__ TypeError: can't pickle IDMEF objects
Do u have any idea how I can fix it?
Greeting Henry
Replies (1)
RE: Error while context gets saved - Added by Antoine LUONG over 8 years ago
Hello,
We are currently working on the problem. In the meantime you can apply the following patch:
diff --git a/preludecorrelator/context.py b/preludecorrelator/context.py
index 9053597..8974594 100644
--- a/preludecorrelator/context.py
+++ b/preludecorrelator/context.py
@@ -101,19 +101,20 @@ class Context(IDMEF, Timer):
FORMAT_VERSION = 0.2
def __setstate__(self, dict):
- Timer.__setstate__(self, dict)
IDMEF.__setstate__(self, dict)
+ Timer.__setstate__(self, dict)
def __init__(self, name, options={}, overwrite=True, update=False, idmef=None):
already_initialized = (update or (overwrite is False)) and hasattr(self, "_name")
if already_initialized is True:
return
- self._version = self.FORMAT_VERSION
- self._options = { "threshold": -1, "expire": 0, "alert_on_expire": False }
IDMEF.__init__(self)
Timer.__init__(self, 0)
+ self._version = self.FORMAT_VERSION
+ self._options = { "threshold": -1, "expire": 0, "alert_on_expire": False }
+
name = getName(name)
self._name = name
self._update_count = 0
@@ -330,7 +331,7 @@ _ctxt_filename = require.get_data_filename("context.dat")
def save():
fd = open(_ctxt_filename, "wb")
- pickle.dump(_CONTEXT_TABLE, fd)
+ pickle.dump(_CONTEXT_TABLE, fd, -1)
fd.close()
def load(_env):
diff --git a/preludecorrelator/idmef.py b/preludecorrelator/idmef.py
index 02f9c6a..dce41a2 100644
--- a/preludecorrelator/idmef.py
+++ b/preludecorrelator/idmef.py
@@ -25,28 +25,6 @@ from preludecorrelator import utils
_RegexType = type(re.compile(""))
class IDMEF(prelude.IDMEF):
- def __setstate__(self, dict):
- fd = tempfile.TemporaryFile("rb+")
- fd.write(dict["idmef_encoded"])
- fd.seek(0)
-
- prelude.IDMEF.__init__(self)
- self.read(fd)
-
- del(dict["idmef_encoded"])
- self.__dict__.update(dict)
-
- def __getstate__(self):
- fd = tempfile.TemporaryFile("rb+")
- self.write(fd)
- fd.seek(0)
-
- odict = self.__dict__.copy()
- odict["idmef_encoded"] = fd.read()
- del(odict["this"])
-
- return odict
-
def getTime(self):
itime = self.get("alert.detect_time")
if not itime:
Regards