Exemplo n.º 1
0
    def api_version(self, request):
        """
        Return current NOC version

        :returns: version string
        :rtype: Str
        """
        return get_version()
Exemplo n.º 2
0
 def api_about(self, request):
     cp = CPClient()
     return {
         "version": get_version(),
         "installation": config.get("customization",
                                    "installation_name"),
         "system_id": cp.system_uuid,
         "copyright": "2007-%d, The NOC Project" % datetime.date.today().year
     }
Exemplo n.º 3
0
Arquivo: test.py Projeto: fossabot/noc
 def test_api_version(self):
     version = get_version()
     # Anonymous
     status, r = self.get("/version/")
     self.assertEqual(status, self.HTTP_OK)
     self.assertEqual(r, version)
     # Authenticated
     status, r = self.get("/version/", user="******")
     self.assertEqual(status, self.HTTP_OK)
     self.assertEqual(r, version)
     # Superuser
     status, r = self.get("/version/", user="******")
     self.assertEqual(status, self.HTTP_OK)
     self.assertEqual(r, version)
Exemplo n.º 4
0
Arquivo: http.py Projeto: fossabot/noc
 def request(self, method, path, params=None, headers={}):
     # Build request
     headers = headers.copy()
     h_keys = set([k.lower() for k in headers])
     if "host" not in headers:
         headers["Host"] = self.address
     headers["Connection"] = "close"
     if "user-agent" not in headers:
         headers["User-Agent"] = "NOC/%s" % get_version()
     r = "%s %s HTTP/1.1\r\n" % (method, path)
     r += "\r\n".join(["%s: %s" % (k, v) for k, v in headers.items()])
     r += "\r\n\r\n"
     self.write(r)
     return self.queue.get(block=True)
Exemplo n.º 5
0
 def get_data(self, **kwargs):
     si = get_connection().server_info()
     versions = [["NOC", get_version()],
                 SectionRow("Host Software"), ["OS", " ".join(os.uname())],
                 ["Python", sys.version],
                 ["PostgreSQL",
                  self.execute("SELECT VERSION()")[0][0]],
                 ["MongoDB",
                  "%s (%dbit)" % (si["version"], si["bits"])]]
     versions += [SectionRow("Python Path")]
     for p in sys.path:
         versions += [("", p)]
     return self.from_dataset(title=self.title,
                              columns=["Component", "Version"],
                              data=versions)
Exemplo n.º 6
0
def urlopen(url, auto_deflate=False):
    """
    urlopen wrapper
    """
    global PROXY

    if url.startswith("http://") or url.startswith("https://"):
        r = urllib2.Request(url,
                            headers={"User-Agent": "NOC/%s" % get_version()})
    else:
        r = url
    if auto_deflate and url.endswith(".gz"):
        u = urllib2.urlopen(r)
        f = cStringIO.StringIO(u.read())
        return gzip.GzipFile(fileobj=f)
    else:
        return urllib2.urlopen(r)
Exemplo n.º 7
0
 def __init__(self):
     self.version = get_version()
     self.rules = {}  # event_class -> [Rule]
     self.back_rules = {}  # event_class -> [Rule]
     self.triggers = {}  # alarm_class -> [Trigger1, .. , TriggerN]
     self.rca_forward = {}  # alarm_class -> [RCA condition, ..., RCA condititon]
     self.rca_reverse = defaultdict(set)  # alarm_class -> set([alarm_class])
     self.alarm_jobs = {}  # alarm_class -> [JobLauncher, ..]
     self.handlers = {}  # alamr class id -> [<handler>]
     logging.info("Running noc-correlator")
     self.scheduler = CorrelatorScheduler(self,
         cleanup=reset_queries)
     self.scheduler.register_job_class(PerformanceReportJob)
     try:
         PerformanceReportJob.submit(self.scheduler,
             key="report", interval=60)
     except self.scheduler.JobExists:
         pass
     #
     Daemon.__init__(self)
     # Tables
     self.NOC_ACTIVATORS = self.get_activators()  # NOC::Activators prefix table
Exemplo n.º 8
0
 def __init__(self):
     global _daemon
     self.start_time = time.time()
     _daemon = self
     self.logger = logging.getLogger(self.daemon_name)
     # Chdir to the root of project
     os.chdir(os.path.join(os.path.dirname(sys.argv[0]), ".."))
     self.prefix = os.getcwd()
     # Parse commandline
     self.opt_parser = optparse.OptionParser()
     self.opt_parser.add_option("-c",
                                "--config",
                                action="store",
                                type="string",
                                dest="config",
                                help="Read config from CONFIG")
     self.opt_parser.add_option("-i",
                                "--instance",
                                action="store",
                                type="string",
                                dest="instance_id",
                                default="0",
                                help="Set instnace id")
     self.opt_parser.add_option("-f",
                                "--foreground",
                                action="store_false",
                                dest="daemonize",
                                default=True,
                                help="Do not daemonize. "
                                "Run at the foreground")
     self.opt_parser.add_option("-V",
                                "--version",
                                action="store_true",
                                dest="show_version",
                                default=False,
                                help="Show daemon version")
     self.setup_opt_parser()
     self.options, self.args = self.opt_parser.parse_args()
     if self.options.show_version:
         print get_version()
         sys.exit(0)
     if len(self.args) < 1 or self.args[0] not in [
             "start", "launch", "stop", "refresh", "manifest"
     ]:
         self.opt_parser.error(
             "You must supply one of start|launch|stop|refresh commands")
     # Read config
     self.pidfile = None
     self.config = None
     self.instance_id = self.options.instance_id
     self.metrics = MetricsHub(
         "noc.%s.%s" % (self.daemon_name, self.instance_id), *self.METRICS)
     self.manhole_status = False
     self.start_delay = 0
     self.load_config()
     # Register signal handlers if any
     for s in [s for s in dir(self) if s.startswith("SIG")]:
         try:
             sig = getattr(signal, s)
         except AttributeError:
             self.logger.error(
                 "Signal '%s' is not supported on this platform" % s)
             continue
         signal.signal(sig, getattr(self, s))
     #atexit.register(self.at_exit)
     if self.use_solutions:
         self.logger.info("Initializing solutions")
         from noc.lib.solutions import init_solutions
         init_solutions()
Exemplo n.º 9
0
 def execute(self):
     return {"vendor": "NOC", "platform": "NOC", "version": get_version()}