pynag / pynag

Python modules and utilities for Nagios plugins and configuration
http://pynag.github.com
GNU General Public License v2.0
177 stars 69 forks source link

save service issues: #145

Closed jamiesun closed 10 years ago

jamiesun commented 10 years ago

save service issues:

   def update_service(self,sid,serv_desc,check_command,sync=True,**kwargs):
        service = self.get_service(sid)
        if not service:
            return Result(1,"service is not exists")

        service.use = kwargs.pop("use")
        service.service_description = serv_desc
        service.check_command = check_command
        service.notifications_enabled = kwargs.pop('notifications_enabled',0)
        service.process_perf_data = kwargs.pop("process_perf_data",1)
        service.max_check_attempts = kwargs.pop("max_check_attempts",1)
        service.normal_check_interval = kwargs.pop("normal_check_interval",5)
        service.retry_check_interval = kwargs.pop("retry_check_interval",1)
        log.info(service)
        for _k,_v in kwargs.items():
            if hasattr(service,_k) and _v:
                setattr(service,_k,_v)        
        service.save()
        ....

normal_check_interval and retry_check_interval can not saved.

log info:

[I 140604 11:04:20 nagutils:301] define service { host_name localhost use generic-service service_description CPU coretemp check_command check_local_temp max_check_attempts 1 notifications_enabled 0 process_perf_data 1 }

palli commented 10 years ago

These attributes are deprecated (you won't find them in the docs). But you can use service.set_attribute instead of setattr(service) and it will work as intended. On Jun 4, 2014 6:25 AM, "jamiesun" notifications@github.com wrote:

save service issues:

def update_service(self,sid,serv_desc,check_command,sync=True,**kwargs): service = self.get_service(sid) if not service: return Result(1,"service is not exists")

    service.use = kwargs.pop("use")
    service.service_description = serv_desc
    service.check_command = check_command
    service.notifications_enabled = kwargs.pop('notifications_enabled',0)
    service.process_perf_data = kwargs.pop("process_perf_data",1)
    service.max_check_attempts = kwargs.pop("max_check_attempts",1)
    service.normal_check_interval = kwargs.pop("normal_check_interval",5)
    service.retry_check_interval = kwargs.pop("retry_check_interval",1)
    log.info(service)
    for _k,_v in kwargs.items():
        if hasattr(service,_k) and _v:
            setattr(service,_k,_v)
    service.save()
    ....

normal_check_interval and retry_check_interval can not saved.

log info:

[I 140604 11:04:20 nagutils:301] define service { host_name localhost use generic-service service_description CPU coretemp check_command check_local_temp max_check_attempts 1 notifications_enabled 0 process_perf_data 1 }

— Reply to this email directly or view it on GitHub https://github.com/pynag/pynag/issues/145.

jamiesun commented 10 years ago

thanks