Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
date Formatted date (%A, %B %d, %Y)
time Formatted time (%I:%M %p (%Z))
unit Canonical unit for metric value
============ ===========
"""
subject = grok.app.config.get("notifications", "subject")
bodyType = "default"
with engine.connect() as conn:
metricObj = repository.getMetric(conn, notificationObj.metric)
if metricObj.datasource == "custom":
bodyType = "custom"
body = open(resource_filename(grok.__name__, os.path.join("../conf",
grok.app.config.get("notifications", "body_" + bodyType)))).read()
body = body.replace("\n", "\r\n") # Ensure windows newlines
# Template variable storage (to be expanded in call to str.format())
templated = dict(notification=notificationObj)
# Metric
templated["metric"] = metricObj
# Instance
templated["instance"] = metricObj.tag_name or metricObj.server
# Date/time
templated["timestampUTC"] = notificationObj.timestamp.strftime(
"%A, %B %d, %Y %I:%M %p")
localtime = localizedTimestamp(notificationObj.timestamp)
templated["timestampLocal"] = localtime.strftime(
def GET(self, path=None): # pylint: disable=R0201,W0613,C0103
# Make sure we have the latest version of configuration
grok.app.config.loadConfig()
grok.app.product.loadConfig()
# prep data
apiKey = grok.app.config.get("security", "apikey")
hostname = socket.gethostname()
isEmbed = path and ("embed/" in path)
params = web.input(hash="", width=720, height=480)
paramHash = params.hash
paramHeight = params.height
paramWidth = params.width
refererUri = web.ctx.env.get("HTTP_REFERER", "")
referer = urlparse(refererUri).hostname or ""
sha1 = hashlib.sha1()
render = web.template.render(os.path.join(grok.app.GROK_HOME,
"resources/templates"))
instanceData = _getInstanceMetadata()
data = {"baseUrl": grok.app.config.get("web", "base_url"),
"embed": {"height": paramHeight,
""" Retrieve current region from AWS and cache the result
NOTE: This used to be retrieved directly into a global variable, which added
significant delays when running unit test on a dev laptop while on a
different network (e.g., from home) and there was no way to patch it.
"""
try:
return _getCurrentRegion.currentRegion
except AttributeError:
pass
instanceDataResult = _queryAvailabilityZone()
if instanceDataResult is not None:
currentRegion = instanceDataResult.text.strip()[:-1]
else:
currentRegion = grok.app.config.get("aws", "default_region")
_getCurrentRegion.currentRegion = currentRegion
return _getCurrentRegion.currentRegion
def __init__(self):
# Make sure we have the latest version of configuration
grok.app.config.loadConfig()
self._log = getExtendedLogger(self.__class__.__name__)
self._modelResultsExchange = (
grok.app.config.get("metric_streamer", "results_exchange_name"))
"id": "i-12345678"
},
... (up to 8 total suggested) ...
],
"alternates": [
{
"region": "us-west-2",
"namespace": "AWS/ELB",
"id": "grok-docs-elb"
},
... (up to 22 total alternatives) ...
]
}
"""
if region is None:
region = config.get("aws", "default_region")
ec2Queue = Queue.Queue()
ec2Thread = threading.Thread(
target=ec2_utils.getSuggestedInstances,
args=(region, ec2Queue, _AWS_INSTANCE_FETCHING_TIME_LIMIT))
ec2Thread.start()
rdsQueue = Queue.Queue()
rdsThread = threading.Thread(
target=rds_utils.getSuggestedInstances,
args=(region, rdsQueue, _AWS_INSTANCE_FETCHING_TIME_LIMIT))
rdsThread.start()
elbQueue = Queue.Queue()
elbThread = threading.Thread(
target=elb_utils.getSuggestedInstances,
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')
)
configuration value) for template value. Values are substituted using
python's `str.format(**data)` function where `data` is a dict
containing the following keys:
============ ===========
Key Description
============ ===========
notification Notification instance
data MetricData row that triggered notification
date Formatted date (%A, %B %d, %Y)
time Formatted time (%I:%M %p (%Z))
unit Canonical unit for metric value
============ ===========
"""
subject = grok.app.config.get("notifications", "subject")
bodyType = "default"
with engine.connect() as conn:
metricObj = repository.getMetric(conn, notificationObj.metric)
if metricObj.datasource == "custom":
bodyType = "custom"
body = open(resource_filename(grok.__name__, os.path.join("../conf",
grok.app.config.get("notifications", "body_" + bodyType)))).read()
body = body.replace("\n", "\r\n") # Ensure windows newlines
# Template variable storage (to be expanded in call to str.format())
templated = dict(notification=notificationObj)
# Metric
templated["metric"] = metricObj