def setUp(self):
     self.headers = getDefaultHTTPHeaders(grok.app.config)
     self.app = TestApp(cloudwatch_api.app.wsgifunc())
     adapter = datasource_adapter_factory.createCloudwatchDatasourceAdapter(
     )
     self.resources = adapter.describeSupportedMetrics()
     self.regions = adapter.describeRegions()
 def setUp(self):
     self.app = TestApp(models_api.app.wsgifunc())
     self.headers = getDefaultHTTPHeaders(grok.app.config)
     data = open(
         os.path.join(grok.app.GROK_HOME, "tests/py/data/app/webservices/models_api_integration_test.json")
     ).read()
     self.modelsTestData = json.loads(data)
Esempio n. 3
0
 def setUp(self):
     self.headers = getDefaultHTTPHeaders(grok.app.config)
     self.app = TestApp(wufoo_api.app.wsgifunc())
     self.instanceData = {
         "version": "2010-08-31",
         "instanceId": "i-d9e211f6",
         "billingProducts": None,
         "accountId": "987654321",
         "kernelId": "aki-88aa75e1",
         "ramdiskId": None,
         "architecture": "x86_64",
         "imageId": "ami-b56a7fdc",
         "pendingTime": "2014-03-20T14:06:46Z",
         "instanceType": "m1.medium",
         "region": "us-east-1",
         "devpayProductCodes": None,
         "privateIp": "10.122.242.151",
         "availabilityZone": "us-east-1d"
     }
     self.postData = data = {
         "name": "User Schmoozer",
         "company": "Numenta, inc.",
         "edition": "Standard",
         "version": grok.__version__.__version__,
         "build": "0",
         "email": "*****@*****.**"
     }
Esempio n. 4
0
    def setUp(self):
        self.headers = getDefaultHTTPHeaders(grok.app.config)
        self.app = TestApp(models_api.app.wsgifunc())
        metric = Mock(
            uid="cebe9fab-f416-4845-8dab-02d292244112",
            datasource="cloudwatch",
            description="The number of database connections in use by "
            "Amazon RDS database",
            server="grokdb2",
            location="us-east-1",
            parameters=app_utils.jsonEncode({
                "region": "us-east-1",
                "DBInstanceIdentifier": "grokdb2"
            }),
            status=1,
            message=None,
            collector_error=None,
            last_timestamp="2013-08-15 21:25:00",
            poll_interval=60,
            tag_name=None,
            model_params=None,
            last_rowid=20277)

        metric.name = "AWS/RDS/DatabaseConnections"
        self.metric = metric
Esempio n. 5
0
 def setUp(self):
     self.app = TestApp(models_api.app.wsgifunc())
     self.headers = getDefaultHTTPHeaders(grok.app.config)
     data = open(
         os.path.join(
             grok.app.GROK_HOME,
             "tests/py/data/app/webservices/models_api_integration_test.json"
         )).read()
     self.modelsTestData = json.loads(data)
Esempio n. 6
0
  def setUpClass(cls):
    cls.autostacksApp = TestApp(autostacks_api.app.wsgifunc())
    cls.cloudwatchApp = TestApp(cloudwatch_api.app.wsgifunc())
    cls.customApp = TestApp(custom_api.app.wsgifunc())
    cls.instancesApp = TestApp(instances_api.app.wsgifunc())
    cls.modelApp = TestApp(models_api.app.wsgifunc())
    cls.headers = getDefaultHTTPHeaders(grok.app.config)

    cls.plaintextPort = config.getint("metric_listener", "plaintext_port")
    cls.apiKey = config.get("security", "apikey")
    def setUp(self):
        self.headers = getDefaultHTTPHeaders(grok.app.config)
        self.app = TestApp(notifications_api.app.wsgifunc())

        # Set up dummy notification assets
        self.deviceId = str(uuid.uuid4())
        self.notificationId = str(uuid.uuid4())

        metricParams = {
            u"region": u"us-east-1",
            u"DBInstanceIdentifier": u"grokdb2"
        }
        self.metric = {
            "uid": u"cebe9fab-f416-4845-8dab-02d292244112",
            "datasource": u"cloudwatch",
            "name": u"AWS/RDS/DatabaseConnections",
            "description": u"The number of database connections in use "
            u"by Amazon RDS database",
            "server": u"grokdb2",
            "location": u"us-east-1",
            "parameters": app_utils.jsonEncode(metricParams),
            "status": 1,
            "message": None,
            "collector_error": None,
            "last_timestamp": u"2013-08-15 21:25:00",
            "poll_interval": 60,
            "tag_name": None,
            "model_params": None,
            "last_rowid": 20277
        }

        self.notification = {
            "uid": self.deviceId,
            "metric": self.metric["uid"],
            "device": self.deviceId,
            "windowsize": 3600,
            "timestamp": datetime.datetime.utcnow(),
            "acknowledged": 0,
            "seen": 0,
            "ses_message_id": None,
            "rowid": 666
        }

        self.settings = {
            "uid": self.deviceId,
            "windowsize": 3600,
            "sensitivity": 0.99999,
            "email_addr": "*****@*****.**",
            "last_timestamp": datetime.datetime.utcnow()
        }
 def setUp(self):
     self.headers = getDefaultHTTPHeaders(grok.app.config)
     self.app = TestApp(annotations_api.app.wsgifunc())
     self.annotation = {
         "uid": "f4aa70b361f04036b0b39530900f38fa",
         "timestamp": "2014-01-25 05:00:00",
         "created": "2014-01-25 07:14:06",
         "device": "device1",
         "user": "******",
         "server": "grokdb2",
         "message": "My annotation",
         "data": None
     }
     # Prepare request as annotation without "uid" or "created" fields
     self.request = self.annotation.copy()
     del self.request["uid"]
     del self.request["created"]
 def setUp(self):
   self.headers = getDefaultHTTPHeaders(grok.app.config)
   self.app = TestApp(annotations_api.app.wsgifunc())
   self.annotation = {
     "uid": "f4aa70b361f04036b0b39530900f38fa",
     "timestamp": "2014-01-25 05:00:00",
     "created": "2014-01-25 07:14:06",
     "device": "device1",
     "user": "******",
     "server": "grokdb2",
     "message": "My annotation",
     "data": None
   }
   # Prepare request as annotation without "uid" or "created" fields
   self.request = self.annotation.copy()
   del self.request["uid"]
   del self.request["created"]
  def setUp(self):
    self.headers = getDefaultHTTPHeaders(grok.app.config)
    self.app = TestApp(notifications_api.app.wsgifunc())

    # Set up dummy notification assets
    self.deviceId = str(uuid.uuid4())
    self.notificationId = str(uuid.uuid4())

    metricParams = {u"region":u"us-east-1", u"DBInstanceIdentifier":u"grokdb2"}
    self.metric = {"uid": u"cebe9fab-f416-4845-8dab-02d292244112",
                   "datasource": u"cloudwatch",
                   "name": u"AWS/RDS/DatabaseConnections",
                   "description": u"The number of database connections in use "
                                  u"by Amazon RDS database",
                   "server": u"grokdb2",
                   "location": u"us-east-1",
                   "parameters": app_utils.jsonEncode(metricParams),
                   "status": 1,
                   "message":None,
                   "collector_error": None,
                   "last_timestamp": u"2013-08-15 21:25:00",
                   "poll_interval": 60,
                   "tag_name": None,
                   "model_params": None,
                   "last_rowid": 20277}

    self.notification = {"uid": self.deviceId,
                         "metric": self.metric["uid"],
                         "device": self.deviceId,
                         "windowsize": 3600,
                         "timestamp": datetime.datetime.utcnow(),
                         "acknowledged": 0,
                         "seen": 0,
                         "ses_message_id": None,
                         "rowid": 666}

    self.settings = {"uid": self.deviceId,
                     "windowsize": 3600,
                     "sensitivity": 0.99999,
                     "email_addr": "*****@*****.**",
                     "last_timestamp": datetime.datetime.utcnow()}
  def setUp(self):
    self.headers = getDefaultHTTPHeaders(grok.app.config)
    self.app = TestApp(models_api.app.wsgifunc())
    metric = Mock(uid="cebe9fab-f416-4845-8dab-02d292244112",
                  datasource="cloudwatch",
                  description="The number of database connections in use by "
                              "Amazon RDS database",
                  server="grokdb2",
                  location="us-east-1",
                  parameters=app_utils.jsonEncode(
                    {"region":"us-east-1", "DBInstanceIdentifier":"grokdb2"}),
                  status=1,
                  message=None,
                  collector_error=None,
                  last_timestamp="2013-08-15 21:25:00",
                  poll_interval=60,
                  tag_name=None,
                  model_params=None,
                  last_rowid=20277)

    metric.name = "AWS/RDS/DatabaseConnections"
    self.metric = metric
    def setUp(self):
        self.headers = getDefaultHTTPHeaders(app_config)
        self.invalidHeaders = getInvalidHTTPHeaders()
        self.app = TestApp(annotations_api.app.wsgifunc())
        self.annotation = {
            "uid": "f4aa70b361f04036b0b39530900f38fa",
            "timestamp": "2014-01-25 05:00:00",
            "created": "2014-01-25 07:14:06",
            "device": "device1",
            "user": "******",
            "server": "us-west-2/AWS/EC2/i-f52075fe",
            "message": "My annotation",
            "data": None
        }
        self.instanceId = "%s/AWS/EC2/%s" % (VALID_EC2_INSTANCES["region"],
                                             VALID_EC2_INSTANCES["instanceId"])

        # Prepare request as annotation without "uid" or "created" fields
        self.request = self.annotation.copy()
        self.request["server"] = self.instanceId
        del self.request["uid"]
        del self.request["created"]
  def setUp(self):
    self.headers = getDefaultHTTPHeaders(app_config)
    self.invalidHeaders = getInvalidHTTPHeaders()
    self.app = TestApp(annotations_api.app.wsgifunc())
    self.annotation = {
        "uid": "f4aa70b361f04036b0b39530900f38fa",
        "timestamp": "2014-01-25 05:00:00",
        "created": "2014-01-25 07:14:06",
        "device": "device1",
        "user": "******",
        "server": "us-west-2/AWS/EC2/i-f52075fe",
        "message": "My annotation",
        "data": None
    }
    self.instanceId = "%s/AWS/EC2/%s" % (
        VALID_EC2_INSTANCES["region"],
        VALID_EC2_INSTANCES["instanceId"])

    # Prepare request as annotation without "uid" or "created" fields
    self.request = self.annotation.copy()
    self.request["server"] = self.instanceId
    del self.request["uid"]
    del self.request["created"]
Esempio n. 14
0
 def setUp(self):
   self.headers = getDefaultHTTPHeaders(grok.app.config)
   self.app = TestApp(wufoo_api.app.wsgifunc())
   self.instanceData = {"version" : "2010-08-31",
                        "instanceId" : "i-d9e211f6",
                        "billingProducts" : None,
                        "accountId" : "987654321",
                        "kernelId" : "aki-88aa75e1",
                        "ramdiskId" : None,
                        "architecture" : "x86_64",
                        "imageId" : "ami-b56a7fdc",
                        "pendingTime" : "2014-03-20T14:06:46Z",
                        "instanceType" : "m1.medium",
                        "region" : "us-east-1",
                        "devpayProductCodes" : None,
                        "privateIp" : "10.122.242.151",
                        "availabilityZone" : "us-east-1d"}
   self.postData = data = {"name": "User Schmoozer",
                           "company": "Numenta, inc.",
                           "edition": "Standard",
                           "version": grok.__version__.__version__,
                           "build": "0",
                           "email": "*****@*****.**"}
 def setUp(self):
     self.headers = getDefaultHTTPHeaders(grok.app.config)
     self.app = TestApp(cloudwatch_api.app.wsgifunc())
Esempio n. 16
0
    def setUpClass(cls):
        """
    Setup steps for all test cases.
    Focus for these is to cover all API checks for ModelDataHandler.
    Hence, this does all setup creating metric, waiting for
    metricData across all testcases, all API call for querying metricData
    will be against single metric created in setup
    Setup Process
    1) Update conf with aws credentials, ManagedTempRepository will not
       work in this test
    2) Select test instance such that its running from longer time,
       We are using instance older than 15 days
    3) Create Metric, wait for min metricData rows to become available
       Set to 100, configurable
    4) Pick testRowId, set it lower value this will make sure to have
       Non NULL value for anomaly_score field for given row while invoking
       GET with consitions, set to 5
    5) Decide queryParams for anomalyScore, to and from timestamp
    """
        cls.headers = getDefaultHTTPHeaders(grok.app.config)

        # All other sevices needs AWS credentials to work
        # Set AWS credentials
        grok.app.config.loadConfig()

        # Select test instance such that its running from longer time
        g_logger.info("Getting long-running EC2 Instances")
        instances = aws_utils.getLongRunningEC2Instances(
            "us-west-2", grok.app.config.get("aws", "aws_access_key_id"),
            grok.app.config.get("aws", "aws_secret_access_key"), 15)
        testInstance = instances[randrange(1, len(instances))]

        createModelData = {
            "region": "us-west-2",
            "namespace": "AWS/EC2",
            "datasource": "cloudwatch",
            "metric": "CPUUtilization",
            "dimensions": {
                "InstanceId": testInstance.id
            }
        }

        # Number of minimum rows
        cls.minDataRows = 100

        cls.app = TestApp(models_api.app.wsgifunc())

        # create test metric
        g_logger.info("Creating test metric; modelSpec=%s", createModelData)
        response = cls.app.put("/",
                               utils.jsonEncode(createModelData),
                               headers=cls.headers)
        postResult = utils.jsonDecode(response.body)
        maxWaitTime = 600
        waitTimeMetricData = 0
        waitAnomalyScore = 0

        # Wait for enough metric data to be available
        cls.uid = postResult[0]["uid"]
        engine = repository.engineFactory()
        with engine.connect() as conn:
            cls.metricData = [
                row for row in repository.getMetricData(conn, cls.uid)
            ]
        with engine.connect() as conn:
            cls.testMetric = repository.getMetric(conn, cls.uid)

        # Confirm that we have enough metricData
        g_logger.info("Waiting for metric data")
        while (len(cls.metricData) < cls.minDataRows
               and waitTimeMetricData < maxWaitTime):
            g_logger.info(
                "not ready, waiting for metric data: got %d of %d ...",
                len(cls.metricData), cls.minDataRows)
            time.sleep(5)
            waitTimeMetricData += 5
            with engine.connect() as conn:
                cls.metricData = [
                    row for row in repository.getMetricData(conn, cls.uid)
                ]

        # taking lower value for testRowId, this will make sure to have
        # Non NULL value for anomaly_score field for given row
        cls.testRowId = 5

        with engine.connect() as conn:
            cls.testMetricRow = (repository.getMetricData(
                conn, cls.uid, rowid=cls.testRowId).fetchone())

        # Make sure we did not receive None etc for anomaly score
        g_logger.info("cls.testMetricRow.anomaly_score=%r",
                      cls.testMetricRow.anomaly_score)
        g_logger.info("waitAnomalyScore=%r", waitAnomalyScore)
        while (cls.testMetricRow.anomaly_score is None
               and waitAnomalyScore < maxWaitTime):
            g_logger.info("anomaly_score not ready, sleeping...")
            time.sleep(5)
            waitAnomalyScore += 5
            with engine.connect() as conn:
                cls.testMetricRow = (repository.getMetricData(
                    conn, cls.uid, rowid=cls.testRowId).fetchone())

        # Decide queryParams for anomalyScore, to and from timestamp
        cls.testAnomalyScore = cls.testMetricRow.anomaly_score
        cls.testTimeStamp = cls.testMetricRow.timestamp
 def setUp(self):
   self.headers = getDefaultHTTPHeaders(grok.app.config)
   self.app = TestApp(anomalies_api.app.wsgifunc())
Esempio n. 18
0
 def setUp(self):
   self.app = TestApp(models_api.app.wsgifunc())
   self.headers = getDefaultHTTPHeaders(grok.app.config)
Esempio n. 19
0
 def setUp(self):
   self.headers = getDefaultHTTPHeaders(grok.app.config)
 def setUp(self):
   self.app = TestApp(models_api.app.wsgifunc())
   self.headers = getDefaultHTTPHeaders(grok.app.config)
   self.data = self.createTestData()
 def setUp(self):
     self.headers = getDefaultHTTPHeaders(grok.app.config)
     self.app = TestApp(cloudwatch_api.app.wsgifunc())
     adapter = datasource_adapter_factory.createCloudwatchDatasourceAdapter()
     self.resources = adapter.describeSupportedMetrics()
     self.regions = adapter.describeRegions()
Esempio n. 22
0
  def setUpClass(cls):
    """
    Setup steps for all test cases.
    Focus for these is to cover all API checks for ModelDataHandler.
    Hence, this does all setup creating metric, waiting for
    metricData across all testcases, all API call for querying metricData
    will be against single metric created in setup
    Setup Process
    1) Update conf with aws credentials, ManagedTempRepository will not
       work in this test
    2) Select test instance such that its running from longer time,
       We are using instance older than 15 days
    3) Create Metric, wait for min metricData rows to become available
       Set to 100, configurable
    4) Pick testRowId, set it lower value this will make sure to have
       Non NULL value for anomaly_score field for given row while invoking
       GET with consitions, set to 5
    5) Decide queryParams for anomalyScore, to and from timestamp
    """
    cls.headers = getDefaultHTTPHeaders(grok.app.config)

    # All other sevices needs AWS credentials to work
    # Set AWS credentials
    grok.app.config.loadConfig()

    # Select test instance such that its running from longer time
    g_logger.info("Getting long-running EC2 Instances")
    instances = aws_utils.getLongRunningEC2Instances("us-west-2",
      grok.app.config.get("aws", "aws_access_key_id"),
      grok.app.config.get("aws", "aws_secret_access_key"), 15)
    testInstance = instances[randrange(1, len(instances))]

    createModelData = {
      "region": "us-west-2",
      "namespace": "AWS/EC2",
      "datasource": "cloudwatch",
      "metric": "CPUUtilization",
      "dimensions": {
        "InstanceId": testInstance.id
      }
    }

    # Number of minimum rows
    cls.minDataRows = 100

    cls.app = TestApp(models_api.app.wsgifunc())

    # create test metric
    g_logger.info("Creating test metric; modelSpec=%s", createModelData)
    response = cls.app.put("/", utils.jsonEncode(createModelData),
     headers=cls.headers)
    postResult = utils.jsonDecode(response.body)
    maxWaitTime = 600
    waitTimeMetricData = 0
    waitAnomalyScore = 0


    # Wait for enough metric data to be available
    cls.uid = postResult[0]["uid"]
    engine = repository.engineFactory()
    with engine.connect() as conn:
      cls.metricData = [row for row
                         in repository.getMetricData(conn, cls.uid)]
    with engine.connect() as conn:
      cls.testMetric = repository.getMetric(conn, cls.uid)

    # Confirm that we have enough metricData
    g_logger.info("Waiting for metric data")
    while (len(cls.metricData) < cls.minDataRows and
           waitTimeMetricData < maxWaitTime):
      g_logger.info("not ready, waiting for metric data: got %d of %d ...",
                    len(cls.metricData), cls.minDataRows)
      time.sleep(5)
      waitTimeMetricData += 5
      with engine.connect() as conn:
        cls.metricData = [row for row
                           in repository.getMetricData(conn, cls.uid)]

    # taking lower value for testRowId, this will make sure to have
    # Non NULL value for anomaly_score field for given row
    cls.testRowId = 5

    with engine.connect() as conn:
      cls.testMetricRow = (repository.getMetricData(conn,
                                                     cls.uid,
                                                     rowid=cls.testRowId)
                          .fetchone())

    # Make sure we did not receive None etc for anomaly score
    g_logger.info("cls.testMetricRow.anomaly_score=%r",
                  cls.testMetricRow.anomaly_score)
    g_logger.info("waitAnomalyScore=%r", waitAnomalyScore)
    while (cls.testMetricRow.anomaly_score is None and
           waitAnomalyScore < maxWaitTime):
      g_logger.info("anomaly_score not ready, sleeping...")
      time.sleep(5)
      waitAnomalyScore += 5
      with engine.connect() as conn:
        cls.testMetricRow = (repository.getMetricData(conn,
                                                      cls.uid,
                                                      rowid=cls.testRowId)
                            .fetchone())

    # Decide queryParams for anomalyScore, to and from timestamp
    cls.testAnomalyScore = cls.testMetricRow.anomaly_score
    cls.testTimeStamp = cls.testMetricRow.timestamp
 def setUp(self):
     self.headers = getDefaultHTTPHeaders(grok.app.config)
     self.app = TestApp(cloudwatch_api.app.wsgifunc())
Esempio n. 24
0
 def setUp(self):
   self.headers = getDefaultHTTPHeaders(grok.app.config)
   self.app = TestApp(webapp.app.wsgifunc())
 def setUp(self):
   self.app = TestApp(instances_api.app.wsgifunc())
   self.headers = getDefaultHTTPHeaders(config)
Esempio n. 26
0
 def setUp(self):
     self.app = TestApp(instances_api.app.wsgifunc())
     self.headers = getDefaultHTTPHeaders(config)