Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

124 lines (108 sloc) 4.378 kb
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2009-2012:
# Gabes Jean,
# Gerhard Lausser,
# Gregory Starck,
# Hartmut Goebel,
# This file is part of Shinken.
# Shinken is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# Shinken is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with Shinken. If not, see <>.
import time
""" TODO: Add some comment about this class for the doc"""
class Comment:
id = 1
properties = {
'entry_time': None,
'persistent': None,
'author': None,
'comment': None,
'comment_type': None,
'entry_type': None,
'source': None,
'expires': None,
'expire_time': None,
'can_be_deleted': None,
# TODO: find a very good way to handle the downtime "ref".
# ref must effectively not be in properties because it points
# onto a real object.
#'ref': None
# Adds a comment to a particular service. If the "persistent" field
# is set to zero (0), the comment will be deleted the next time
# Shinken is restarted. Otherwise, the comment will persist
# across program restarts until it is deleted manually.
def __init__(self, ref, persistent, author, comment, comment_type, entry_type, source, expires, expire_time): = += 1
self.ref = ref # pointer to srv or host we are apply
self.entry_time = int(time.time())
self.persistent = persistent = author
self.comment = comment
# Now the hidden attributes
self.comment_type = comment_type
self.entry_type = entry_type
self.source = source
self.expires = expires
self.expire_time = expire_time
self.can_be_deleted = False
def __str__(self):
return "Comment id=%d %s" % (, self.comment)
# Call by pickle for dataify the ackn
# because we DO NOT WANT REF in this pickleisation!
def __getstate__(self):
cls = self.__class__
# id is not in *_properties
res = {'id':}
for prop in
if hasattr(self, prop):
res[prop] = getattr(self, prop)
return res
# Inverted funtion of getstate
def __setstate__(self, state):
cls = self.__class__
# Maybe it's not a dict but a list like in the old 0.4 format
# so we should call the 0.4 function for it
if isinstance(state, list):
return = state['id']
for prop in
if prop in state:
setattr(self, prop, state[prop])
# to prevent from duplicating id in comments:
if >= = + 1
# This function is DEPRECATED and will be removed in a future version of
# Shinken. It should not be useful any more after a first load/save pass.
# Inverted funtion of getstate
def __setstate_deprecated__(self, state):
cls = self.__class__
# Check if the len of this state is like the previous,
# if not, we will do errors!
# -1 because of the 'id' prop
if len( != (len(state) - 1):
self.debug("Passing comment")
return = state.pop()
for prop in
val = state.pop()
setattr(self, prop, val)
if >= = + 1
Jump to Line
Something went wrong with that request. Please try again.