Пример #1
0
 def instance_to_dict(self, mo, fields=None):
     job = Job.get_job_data(
         "discovery",
         jcls="noc.services.discovery.jobs.box.job.BoxDiscoveryJob",
         key=mo.id,
         pool=mo.pool.name,
     )
     last_update = mo.config.get_revisions(reverse=True)
     if last_update:
         last_update = humanize_distance(last_update[0].ts)
     last_success = "--"
     last_status = None
     if job:
         last_success = humanize_distance(
             job["last"]) if "last" in job else "--"
         last_status = job["ls"] if "ls" in job else None
     return {
         "id": str(mo.id),
         "name": mo.name,
         "profile_name": mo.profile.name,
         "last_success": last_success,
         "status": job["s"] if job else "--",
         "last_status": last_status,
         "last_update": last_update if last_update else None,
     }
Пример #2
0
    def api_discovery(self, request, id):
        from noc.core.scheduler.job import Job

        o = self.get_object_or_404(ManagedObject, id=id)
        if not o.has_access(request.user):
            return self.response_forbidden("Access denied")
        link_count = defaultdict(int)
        for link in Link.object_links(o):
            m = link.discovery_method or ""
            if "+" in m:
                m = m.split("+")[0]
            link_count[m] += 1
        r = [{
            "name": "ping",
            "enable_profile": o.object_profile.enable_ping,
            "status": o.get_status(),
            "last_run": None,
            "last_status": None,
            "next_run": None,
            "jcls": None,
        }]

        for name, jcls in self.DISCOVERY_JOBS:
            job = Job.get_job_data(
                "discovery", jcls=jcls, key=o.id, pool=o.pool.name) or {}
            d = {
                "name":
                name,
                "enable_profile":
                getattr(o.object_profile, "enable_%s_discovery" % name),
                "status":
                job.get(Job.ATTR_STATUS),
                "last_run":
                self.to_json(job.get(Job.ATTR_LAST)),
                "last_status":
                job.get(Job.ATTR_LAST_STATUS),
                "next_run":
                self.to_json(job.get(Job.ATTR_TS)),
                "jcls":
                jcls,
            }
            r += [d]
        return r
Пример #3
0
 def instance_to_dict(self, mo, fields=None):
     job = Job.get_job_data(
         "discovery",
         jcls="noc.services.discovery.jobs.box.job.BoxDiscoveryJob",
         key=mo.id,
         pool=mo.pool.name)
     last_update = mo.config.get_revisions(reverse=True)
     if last_update:
         last_update = humanize_distance(last_update[0].ts)
     last_success = '--'
     last_status = None
     if job:
         last_success = humanize_distance(
             job["last"]) if "last" in job else '--'
         last_status = job["ls"] if "ls" in job else None
     return {
         'id': str(mo.id),
         'name': mo.name,
         'profile_name': mo.profile.name,
         'last_success': last_success,
         'status': job["s"] if job else '--',
         'last_status': last_status,
         'last_update': last_update if last_update else None
     }