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, }
def instance_to_dict(self, o, fields=None): last_success = humanize_distance(o.ts) if o.ts else '--' mo = ManagedObject.objects.get(id=o.object) last_update = mo.config.get_revisions(reverse=True) if last_update: last_update = humanize_distance(last_update[0].ts) return { 'id': str(mo.id), 'name': mo.name, 'profile_name': mo.profile_name, 'last_success': last_success, 'status': o.status, 'last_status': o.last_status, 'last_update': last_update if last_update else None }
def get_data(self, **kwargs): old = datetime.datetime.now() - datetime.timedelta( minutes=self.STALE_INTERVAL) data = [] for pool in Pool._get_collection().find({}, {"_id": 0, "name": 1}): scheduler = Scheduler("discovery", pool=pool["name"]) for r in scheduler.get_collection().find({ "runs": { "$gt": 1 }, "jcls": { "$regex": "_discovery$" }, "st": { "$lte": old } }): mo = ManagedObject.get_by_id(r["key"]) if not mo or not mo.is_managed: continue msg = "" if r["tb"]: tb = r["tb"] if "text" in tb and "code" in tb: if tb["text"].endswith("END OF TRACEBACK"): tb["text"] = "Job crashed" msg = "(%s) %s" % (tb["text"], tb["code"]) data += [[ mo.administrative_domain.name, mo.name, mo.profile.name, mo.platform.name, mo.version.name, mo.address, mo.segment.name, r["jcls"], humanize_distance(r["st"]), msg, ]] return self.from_dataset( title=self.title, columns=[ _("Admin. Domain"), _("Object"), _("Profile"), _("Platform"), _("Version"), _("Address"), _("Segment"), _("Job"), _("Last Success"), _("Reason"), ], data=sorted(data), enumerate=True, )
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 }
def get_data(self, **kwargs): old = datetime.datetime.now() - \ datetime.timedelta(minutes=self.STALE_INTERVAL) s = get_db()["noc.schedules.inv.discovery"] data = [] for r in s.find({ "runs": { "$gt": 1 }, "jcls": { '$regex': '_discovery$' }, "st": { "$lte": old } }).sort("jcls"): mo = ManagedObject.objects.get(id=r['key']) msg = "" if r["tb"]: tb = r["tb"] if "text" in tb and "code" in tb: if tb["text"].endswith("END OF TRACEBACK"): tb["text"] = "Job crashed" msg = "(%s) %s" % (tb["text"], tb["code"]) if mo.name == "SAE" or not mo.is_managed: continue data += [[ mo.administrative_domain.name, mo.name, mo.profile_name, mo.platform, mo.address, r['jcls'], humanize_distance(r["st"]), msg ]] return self.from_dataset(title=self.title, columns=[ "Admin. Domain", "Object", "Profile", "Platform", "Address", "Script", "Last Success", "Reason" ], data=sorted(data), enumerate=True)