How to use the grok.app.config function in grok

To help you get started, we’ve selected a few grok examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github numenta / numenta-apps / grok / bin / test_model_size.py View on Github external
if __name__ == "__main__":
  parser = optparse.OptionParser()
  parser.add_option("--server", default="https://localhost",
                    help="Server address of Grok instance.")
  parser.add_option("--apiKey", default=None,
                    help="API key for the Grok instance.")
  parser.add_option("--metricName", default=None,
                    help="Name to give the new metric.")
  parser.add_option("--resource", default=None,
                    help="Name to give the new metric.")
  parser.add_option("-n", "--numRecords", default=DEFAULT_RECORDS,
                    type="int", help="The number of records to send.")
  options, _ = parser.parse_args()

  apiKey = options.apiKey or config.get("security", "apikey")
  metricName = options.metricName or "test.%f" % time.time()

  run(options.server, apiKey, metricName, options.resource, options.numRecords)
github numenta / numenta-apps / grok / bin / upload_logs.py View on Github external
def run(logDir, force=False):
  """Upload logs from the specified directory if the customer is opted in."""
  # Ensure that logs are uploaded only for customers opted in.
  optedIn = config.get("usertrack", "optin") == "true"
  if not force and not optedIn:
    _LOGGER.info("Customer is not opted into log uploading, exiting.")
    sys.exit(0)

  conn = boto.connect_s3(_AWS_ACCESS_KEY, _AWS_SECRET_KEY)
  bucket = conn.get_bucket(_BUCKET, validate=False)
  _uploadLogs(bucket, logDir, _ROTATION_FORMAT)
github numenta / numenta-apps / grok / grok / app / webservices / settings_api.py View on Github external
def validSections(self):
    # Make sure we have the latest version of configuration
    grok.app.config.loadConfig()
    if grok.app.config.has_option("admin", "configurable_sections"):
      return grok.app.config.get("admin", "configurable_sections").split(",")
    else:
      return []
github numenta / numenta-apps / grok / grok / app / runtime / aggregator_utils.py View on Github external
def getAWSCredentials():
  # Reload config, if it changed
  grok.app.config.loadConfig()

  return dict(
    aws_access_key_id=grok.app.config.get("aws", "aws_access_key_id"),
    aws_secret_access_key=grok.app.config.get("aws", 'aws_secret_access_key')
  )
github numenta / numenta-apps / grok / grok / app / webservices / webapp.py View on Github external
"result": ("Please use the same AWS Credentials that you "
                         "initially authenticated with.")
          })

    try:
      checkEC2Authorization(data["aws_access_key_id"],
                            data["aws_secret_access_key"])
    except (AuthFailure, AWSPermissionsError) as e:
      raise UnauthorizedResponse({"result": str(e)})

    result = {"result": "success"}

    apikey = None

    if grok.app.config.has_section("security"):
      if grok.app.config.has_option("security", "apikey"):
        apikey = grok.app.config.get("security", "apikey")

    if not apikey:
      apikey = self.generateAPIKey()
      grok.app.config.set("security", "apikey", apikey)
      grok.app.config.save()

    result["apikey"] = apikey

    web.header("Content-Type", "application/json; charset=UTF-8", True)
    return encodeJson(result)
github numenta / numenta-apps / grok / grok / app / runtime / metric_collector.py View on Github external
def __init__(self):
    self._log = grok_logging.getExtendedLogger(self.__class__.__name__)

    self._profiling = (
      grok.app.config.getboolean("debugging", "profiling") or
      self._log.isEnabledFor(logging.DEBUG))

    self._pollInterval = grok.app.config.getfloat(
      "metric_collector", "poll_interval")

    self._metricErrorGracePeriod = grok.app.config.getfloat(
      "metric_collector", "metric_error_grace_period")

    # Interval for periodic garbage collection of our caches (e.g.,
    # self._metricInfoCache and self._resourceInfoCache)
    self._cacheGarbageCollectionIntervalSec = self._metricErrorGracePeriod * 2

    # Time (unix epoch) when to run the next garbage collection of
    # self._metricInfoCache and self._resourceInfoCache; 0 triggers it ASAP as a
    # quick test of the logic. See self._cacheGarbageCollectionIntervalSec.
    self._nextCacheGarbageCollectionTime = 0
github numenta / numenta-apps / grok / grok / app / webservices / logging_api.py View on Github external
from htmengine import utils
from grok.app.repository import schema
from grok.app.aws import s3_utils
from grok import grok_logging

from nta.utils.file_lock import ExclusiveFileLock



# Path format for writing Android logs.
_LOG_FORMAT_ANDROID = os.path.join(os.path.dirname(grok.__file__), "..",
                                   "logs", "android.log")
_LOGGER = grok_logging.getExtendedLogger(__name__)

_AWS_ACCESS_KEY = config.get("aws", "aws_access_key_id")
_AWS_SECRET_KEY = config.get("aws", "aws_secret_access_key")
_BUCKET = "grok.logs"
_MACHINE_ID = uuid.getnode()
_KEY_PREFIX = "metric_dumps/%s-" % _MACHINE_ID
_UPLOAD_ATTEMPTS = 3

urls = (
  # /_logging/android
  "/android", "AndroidHandler",
  # /_logging/feedback
  "/feedback", "FeedbackHandler",
)



class AndroidHandler(object):
github numenta / numenta-apps / grok / grok / app / aws / ses_utils.py View on Github external
def sendEmail(subject, body, toAddresses, region=None, sender=None):
  """Send an email with AWS SES.

  :param subject: Email subject header
  :param body: Email body
  :param toAddresses: Email recipient(s)
  :param region: AWS Region
  :param sender: Email sender
  :returns: SES Message ID or None
  """
  if region is None:
    region = config.get("aws", "default_region")

  if sender is None:
    sender = config.get("notifications", "sender")

  if region not in _SES_ENDPOINTS:
    raise ValueError("Region '%s' provided does not exist in known SES region "
                     "endpoints set." % region)

  regionInfo = RegionInfo(None, region, _SES_ENDPOINTS[region])

  awsAccessKeyId = config.get("notifications", "aws_access_key_id")
  awsSecretAccessKey = config.get("notifications", "aws_secret_access_key")
  if awsAccessKeyId == "" or awsSecretAccessKey == "":
    awsAccessKeyId = config.get("aws", "aws_access_key_id")
    awsSecretAccessKey = config.get("aws", "aws_secret_access_key")
github numenta / numenta-apps / grok / grok / app / runtime / aggregator_utils.py View on Github external
def getAWSCredentials():
  # Reload config, if it changed
  grok.app.config.loadConfig()

  return dict(
    aws_access_key_id=grok.app.config.get("aws", "aws_access_key_id"),
    aws_secret_access_key=grok.app.config.get("aws", 'aws_secret_access_key')
  )
github numenta / numenta-apps / grok / grok / app / webservices / handlers.py View on Github external
def compareAuthorization(userAPIKey):
    """ Returns bool, or None if not applicable.  Therefore, not suitable for
    blind bool evaluation... """
    grok.app.config.loadConfig()
    if grok.app.config.has_section("security"):
      try:
        validAPIKey = grok.app.config.get("security", "apikey")
      except ConfigParser.NoOptionError:
        raise Exception("Internal error, could not get config apikey...")

      return userAPIKey == validAPIKey

    return None