def print_environment(): # Print scalyr-related env variables in sorted order with critical variables up top. Redact API key. main_keys = ["SCALYR_API_KEY", "SCALYR_SERVER"] special_case_keys = set(["K8S_EVENT_DISABLE"]) redacted_keys = set(["SCALYR_API_KEY"]) # Make a map of uppercase keys -> relevant environment vars (beginning with SCALYR) upper2actualkey = {} for k in os.environ.keys(): kup = k.upper() if kup.startswith("SCALYR") or kup in special_case_keys: upper2actualkey[kup] = k # Sorted list of all scalyr keys, including main_keys which may not be present # Sort order does not consider letter case. sorted_upperkeys = main_keys + sorted( set(upper2actualkey.keys()) - set(main_keys) ) print("", file=output) row = 0 for kup in sorted_upperkeys: key = upper2actualkey.get(kup, kup) val = compat.os_getenv_unicode(key) if not val: val = "<Missing>" elif key.upper() in redacted_keys: val = "<Redacted>" if row == 0: print("Environment variables: %s = %s" % (key, val), file=output) else: print(" %s = %s" % (key, val), file=output) row += 1
def get_env_throw_if_not_set(name, default_value=None): # type: (str, Optional[str]) -> str """ Return provided environment variable value and throw if it's not set. """ value = compat.os_getenv_unicode(name, default_value) if value is None: raise ValueError("Environment variable '%s' not set" % (name)) return value
Script which uploads coverage data files to a S3 bucket. """ from __future__ import absolute_import from __future__ import print_function import os import sys import time import random from libcloud.storage.types import Provider from libcloud.storage.providers import get_driver from scalyr_agent import compat BUCKET_NAME = compat.os_getenv_unicode("COVERAGE_BUCKET_NAME", "scalyr-agent-2-coverage-data") ACCESS_KEY_ID = compat.os_getenv_unicode("COVERAGE_AWS_ACCESS_KEY_ID", None) ACCESS_KEY_SECRET = compat.os_getenv_unicode("COVERAGE_AWS_ACCESS_KEY_SECRET", None) AWS_REGION = compat.os_getenv_unicode("COVERAGE_AWS_REGION", "us-east-1") CIRCLE_CI_BRANCH = compat.os_getenv_unicode("CIRCLE_BRANCH", None) CIRCLE_CI_COMMIT = compat.os_getenv_unicode("CIRCLE_SHA1", None) if not ACCESS_KEY_ID: raise ValueError("COVERAGE_AWS_ACCESS_KEY_ID env variable not set") if not ACCESS_KEY_SECRET: raise ValueError("COVERAGE_AWS_ACCESS_KEY_SECRET env variable not set")
import uuid import datetime import argparse import time from io import open from pprint import pprint from urllib.parse import urlparse from urllib.parse import urlencode from urllib.parse import quote_plus import requests from scalyr_agent import compat SCALYR_TOKEN = compat.os_getenv_unicode("SCALYR_TOKEN") SCALYR_WRITE_TOKEN = compat.os_getenv_unicode("SCALYR_WRITE_TOKEN") SCALYR_READ_TOKEN = compat.os_getenv_unicode("SCALYR_READ_TOKEN") SCALYR_URL = compat.os_getenv_unicode("SCALYR_URL") assert SCALYR_WRITE_TOKEN is not None assert SCALYR_URL is not None if not SCALYR_URL.endswith("/addEvents"): SCALYR_URL += "/addEvents" BASE_HEADERS = { "Content-Type": "application/json", }
] # List of API urls to test API_URLS = [ # Prod US "https://scalyr.com/addEvents", "https://www.scalyr.com/addEvents", "https://agent.scalyr.com/addEvents", # Prod EU "https://eu.scalyr.com/addEvents", "https://upload.eu.scalyr.com/addEvents", # Staging EU "https://logstaging.eu.scalyr.com/addEvents", ] SCALYR_TOKEN_PROD_US = compat.os_getenv_unicode("SCALYR_TOKEN_PROD_US") SCALYR_TOKEN_PROD_EU = compat.os_getenv_unicode("SCALYR_TOKEN_PROD_EU") SCALYR_TOKEN_STAGING_EU = compat.os_getenv_unicode("SCALYR_TOKEN_STAGING_EU") if not SCALYR_TOKEN_PROD_US: raise ValueError("SCALYR_TOKEN_PROD_US environment variable not set") if not SCALYR_TOKEN_PROD_EU: raise ValueError("SCALYR_TOKEN_PROD_EU environment variable not set") if not SCALYR_TOKEN_STAGING_EU: raise ValueError("SCALYR_TOKEN_STAGING_EU environment variable not set") BASE_HEADERS = { "Content-Type": "application/json",
if False: from typing import List from typing import Tuple from io import open import os import sys import glob import json import requests from scalyr_agent import compat SLACK_CHANNEL = compat.os_getenv_unicode("SLACK_CHANNEL", "#cloud-tech") SLACK_WEBHOOK = compat.os_getenv_unicode("SLACK_WEBHOOK", None) CIRCLE_BRANCH = compat.os_getenv_unicode("CIRCLE_BRANCH", "unknown") CIRCLE_COMMIT = compat.os_getenv_unicode("CIRCLE_SHA1", "unknown") GITHUB_VIEW_COMMIT_URL = "https://github.com/scalyr/scalyr-agent-2/commit/%s" if not SLACK_WEBHOOK: raise ValueError("SLACK_WEBHOOK environment variable not set") BASE_PAYLOAD = { "channel": SLACK_CHANNEL, "attachments": [{ "text":
def get_config_from_env( param_name, custom_env_name=None, convert_to=None, logger=None, param_val=None, monitor_name=None, ): """Returns the environment variable value for a config param. Warn on conflicts between config and env values. If a custom environment variable name is defined, use it instead of prepending 'SCALYR_'. @param param_name: Config param name (may be global or module-level) @param custom_env_name: Custom environment variable name @param expected_type: If not None, will convert and validate to this type. Otherwise, will leave as string. @param logger :(Optional) If non-null, warn on conflicts between param_val and environment value @param param_val: (Optional) Config param value to compare with to warn on conflict. @param monitor_name: (Optional) Additional context identifying which monitor the param belongs to. If none, indicates global param. @return: An object representing the converted environment value. @raise BadConfiguration if cannot be converted to expected_type """ env_name = custom_env_name if not env_name: env_name = "SCALYR_%s" % param_name env_name = env_name.upper() # 2->TODO in python2 os.getenv returns 'str' type. Convert it to unicode. strval = compat.os_getenv_unicode(env_name) if strval is None: env_name = env_name.lower() strval = compat.os_getenv_unicode(env_name) if strval is None or convert_to is None: return strval converted_val = convert_config_param( param_name, strval, convert_to, is_environment_variable=True ) # Report conflicting values if logger: if param_val is not None and param_val != converted_val: logger.warn( "Conflicting values detected between %s config file parameter `%s` and the environment variable `%s`. " "Ignoring environment variable." % (monitor_name or "global", param_name, env_name), limit_once_per_x_secs=300, limit_key="config_conflict_%s_%s_%s" % (monitor_name or "global", param_name, env_name), ) # Extra logging for critical params if param_val is None: if param_name == "api_key": logger.debug( "Using the api key from environment variable `%s`" % env_name, limit_once_per_x_secs=300, limit_key="api_key_from_env", ) return converted_val
from __future__ import absolute_import from __future__ import print_function import copy import requests from scalyr_agent.util import SUPPORTED_COMPRESSION_ALGORITHMS from scalyr_agent.util import COMPRESSION_TYPE_TO_DEFAULT_LEVEL from scalyr_agent.util import get_compress_and_decompress_func from benchmarks.micro.utils import generate_add_events_request from scalyr_agent import compat SCALYR_TOKEN = compat.os_getenv_unicode("SCALYR_TOKEN") SCALYR_URL = compat.os_getenv_unicode("SCALYR_URL") assert SCALYR_TOKEN is not None assert SCALYR_URL is not None if not SCALYR_URL.endswith("/addEvents"): SCALYR_URL += "/addEvents" BASE_HEADERS = { "Content-Type": "application/json", } BASE_BODY = {"token": SCALYR_TOKEN, "session": "session", "threads": []}