def get_executable_temp_file(command, event_id): """ Saves the given command into a file file so that it can be executed directly. """ try: # Replace all new lines with carriage returns. path = os_sep_join(AGENT_OUTPUT_DIR, event_id + "_cmd") temp_file = open(path, "w+") temp_file.write(command) temp_file.close() # Make the file executable. st = os.stat(path) os.chmod(path, st.st_mode | S_IEXEC) return path except Exception: _, e, _ = sys.exc_info() nlogger.error("Cannot write to a temporary file. Error: %s", repr(e)) return None
def get_temp_batch_file_for_windows(command): """ Saves the given command into a batch file on Windows after taking care of new line conversions for windows. This method should only be invoked on Windows. """ try: # Replace all new lines with carriage returns. text = command.replace("\n", "\r\n") path = os_sep_join(AGENT_OUTPUT_DIR, "command.bat") temp_file = open(path, "w+") temp_file.write(text) temp_file.close() # Make the file executable. st = os.stat(path) os.chmod(path, st.st_mode | S_IEXEC) return path except Exception: _, e, _ = sys.exc_info() nlogger.error("Cannot write to a temporary file. Error: %s", repr(e)) return None
from boto.sqs.message import RawMessage from logging.handlers import RotatingFileHandler from os.path import join as os_sep_join from subprocess import Popen from stat import S_IEXEC # Force use of pyopenssl try: import urllib3.contrib.pyopenssl urllib3.contrib.pyopenssl.inject_into_urllib3() except ImportError: pass AGENT_VERSION = "1.0.0" USER_HOME = os.path.expanduser("~") AGENT_HOME = os_sep_join(USER_HOME, "neptuneio") DEFAULT_CONFIG_FILE = os_sep_join(AGENT_HOME, "nagent.cfg") LOG_FILE_PATH = os_sep_join(AGENT_HOME, "nagent.log") AGENT_STATUS_FILE_PATH = os_sep_join(AGENT_HOME, ".status") AGENT_OUTPUT_DIR = os_sep_join(AGENT_HOME, "output") AGENT_EVENT_LIST_FILE = os_sep_join(AGENT_OUTPUT_DIR, ".nagent_events") PLATFORM_INFO = platform.platform() WINDOWS_OS_NAME = 'nt' # Agent operation settings LOGROTATE_MAX_SIZE = 10000000 # 10MB LOGROTATE_NUM_FILES = 5 AGENT_HEALTH_CHECK_PERIOD = 3600 # 1 hour AGENT_REGISTRATION_RETRY_INTERVAL = 5 * 60 # 5 min NUM_RETRIES_FOR_SQS_CONNECT = 5 NUM_MSGS_TO_FETCH_FROM_SQS = 10