Tanium Kit - Collection of python utility modules.
tanium_kit.
text_type
¶alias of unicode
tanium_kit.ask.
NO_LIST
= [u'no', u'n', u'false', u'0', 0, False]¶List of possible “No” strings.
tanium_kit.ask.
YES_LIST
= [u'yes', u'y', u'ye', u'true', u'1', 1, True]¶List of possible “True” strings.
tanium_kit.excel_writer.
ExcelWriter
[source]¶Bases: object
CSV
= u''¶HEADERS
= []¶MSGS
= []¶ROWS
= []¶tanium_kit.excel_writer.
ExcelWriterError
[source]¶Bases: exceptions.Exception
Interactive python console with full auto complete, history, and history file support.
tanium_kit.history_console.
HistoryConsole
(locals=None, **kwargs)[source]¶Bases: code.InteractiveConsole
Interactive python console with full auto complete, history, and history file support.
Examples
>>> HistoryConsole()
FILENAME
= u'<console>'¶HISTFILE
= u'~/.console-history'¶IniReader.
tanium_kit.ini_reader.
IniReader
[source]¶Bases: object
IniReader.
BOOL_OPTS
= [u'true', u'false', u'yes', u'no', u'on', u'off', 0, u'0', 1, u'1']¶BOOL_TRUE
= [u'true', u'yes', u'on', 1, u'1']¶TEXT_PRE
= u'__TEXT::'¶_parser_type
¶alias of RawConfigParser
_value_cache
= {}¶tanium_kit.ini_reader.
IniReaderError
[source]¶Bases: exceptions.Exception
Reader exceptions.
Die.
tanium_kit.log_filters.
RegexLogFilter
(search_regex, **kwargs)[source]¶Bases: logging.Filter
Die.
_EXC
= None¶_MODES
= [u'skip', u'include', u'replace']¶_TATTRS
= [u'filter_mode', u'search_regex', u'replace_regex', u'description']¶_TMPL_EXC
= u'EXCEPTION {} in {}'¶_TMPL_MODES
= u'skip, include, replace'¶_TMPL_NEWEXC
= u'{}\n!!!! WRAPPED INITIAL {}'¶_TMPL_PREVEXC
= u'{}\n!!!! WRAPPED PREVIOUS {}'¶_TMPL_THIS
= u"Log Filter filter_mode: '{filter_mode}', search_regex: '{search_regex}', replace_regex: '{replace_regex}', description: '{description}'"¶_TSTR
= u"filter_mode: '{filter_mode}', search_regex: '{search_regex}', replace_regex: '{replace_regex}', description: '{description}'"¶description
= u'No description provided!'¶filter_mode
= u'skip'¶k
= u'description'¶replace_regex
= u''¶search_regex
= None¶test_str
= u'ABCDEFGHIJKLMNOPQRSTUVWXYZ'¶valid_test
= u''¶Die.
Notes
The tanium log will show LEVEL at the appropriate tanium log levels according to TaniumHandler.LOG_TAN_LVL_MAP.
When running from Taniums embedded python interpreter, stdout is not captured!
tanium_kit.log_tanium.
LOG_TAN_FORMAT
= u'[%(name)s] %(levelname)-8s %(message)s'¶Format for the tanium log output.
tanium_kit.log_tanium.
LOG_TAN_HANDLER_NAME
= u'tanium_handler'¶Name to label tanium handler with.
tanium_kit.log_tanium.
LOG_TAN_LEVEL
= u'DEBUG'¶Set the tanium handler to DEBUG, let the logger control the actual level.
tanium_kit.log_tanium.
TaniumHandler
(**kwargs)[source]¶Bases: logging.Handler
Python logging handler for tanium logging that can be added to a python logger.
LOG_TAN_DEFAULT_LVL
= 0¶Show python logging levels that do not match in LOG_TAN_LVL_MAP in tanium log at level 0.
LOG_TAN_LVL_MAP
= {40: 0, 10: 40, 20: 20, 50: 0, 30: 0}¶Map of python logging levels to tanium logging levels.
tanium_kit.log_tanium.
TaniumStream
[source]¶Bases: object
Fake stream object for TaniumHandler.
tanium_kit.log_tanium.
make_handler_tan
(logger, **kwargs)[source]¶Create and add a tanium output handler object to a logger.
Parameters: |
|
---|---|
Returns: | handler –
|
Return type: | python logging handler object |
Helper class for the python logging system.
tanium_kit.log_tools.
LOGGER_LEVEL
= u'DEBUG'¶Level to set logger to.
tanium_kit.log_tools.
LOGGER_NAME
= u'logger'¶Used to track name of logger.
tanium_kit.log_tools.
LOGGER_PATH
= u''¶Path of python logger to fetch, empty fetches the root logger.
tanium_kit.log_tools.
LOG_CON_FORMAT
= u'[%(name)s] %(levelname)-8s %(message)s'¶Format for the console output.
tanium_kit.log_tools.
LOG_CON_HANDLER_NAME
= u'console_handler'¶Name to label console handler with.
tanium_kit.log_tools.
LOG_CON_LEVEL
= u'DEBUG'¶Set the console handler to DEBUG, let the logger control the actual level.
tanium_kit.log_tools.
LOG_CON_OUTPUT
= <open file '<stdout>', mode 'w'>¶Send console output to stdout.
tanium_kit.log_tools.
LOG_FILE_COUNT
= 5¶Number of rolled over file logs to keep.
tanium_kit.log_tools.
LOG_FILE_DIR
= u''¶Directory to store log files, if not absolute will be joined with cwd.
tanium_kit.log_tools.
LOG_FILE_FORMAT
= u'%(asctime)s [%(name)s] %(levelname)-8s %(message)s'¶Format for the file log output
tanium_kit.log_tools.
LOG_FILE_HANDLER_NAME
= u'log_file_handler'¶Name to label tanium handler with.
tanium_kit.log_tools.
LOG_FILE_LEVEL
= u'DEBUG'¶Set the file handler to DEBUG, let the logger control the actual level.
tanium_kit.log_tools.
LOG_FILE_MB
= 10¶MB of file log size before rollover.
tanium_kit.log_tools.
LOG_FILE_NAME
= u''¶File name to use for file log, if not supplied the basename of LOGGER_NAME will be used.
tanium_kit.log_tools.
LOG_GMTIME
= True¶Configure pythons logging interface to use gmtime for standardization.
tanium_kit.log_tools.
_remove_handler
(logger, handler)[source]¶Wrapper method to close file handles properly and remove handler from a logger.
Parameters: |
|
---|
tanium_kit.log_tools.
add_handler
(logger, handler)[source]¶Add a handler object to a logger.
Parameters: |
|
---|
tanium_kit.log_tools.
config_verbosity
(pre, verbosity)[source]¶Configure verbose loggers depending on verbosity.
tanium_kit.log_tools.
get_handler
(logger, handler_name)[source]¶Retrieve a handler object from a logger by name.
Parameters: |
|
---|---|
Returns: | ret –
|
Return type: | obj or None |
tanium_kit.log_tools.
make_handler_con
(logger, **kwargs)[source]¶Create and add a console output handler object to a logger.
Parameters: |
|
---|---|
Returns: | handler –
|
Return type: | python logging handler object |
tanium_kit.log_tools.
make_handler_file
(logger, **kwargs)[source]¶Create and add a file output handler object to a logger.
Parameters: |
|
---|---|
Returns: | handler –
|
Return type: | python logging handler object |
tanium_kit.log_tools.
make_logger
(**kwargs)[source]¶Create and add a file output handler object to a logger.
Parameters: |
|
---|---|
Returns: | logger –
|
Return type: | python logging logger object |
tanium_kit.log_tools.
remove_all_handlers
(logger)[source]¶Remove all handlers from a logger.
Parameters: | logger (python logging logger object) –
|
---|
tanium_kit.log_tools.
remove_handler
(logger, handler_name)[source]¶Remove a handler by name from a logger.
Parameters: |
|
---|
tanium_kit.log_tools.
set_format
(o, **kwargs)[source]¶Configure a python logging objects logging format.
Parameters: |
---|
Homegrown utility libraries for tanium_pam4.
tanium_kit.pretty.
GUESS_MAP
= {u'{': u'json', u'[': u'json', u'<': u'xml'}¶Dict that maps first character in text
to a given type if text_type
== ‘guess’.
tanium_kit.pretty.
TEXT_TYPE_MAP
= {u'xml': [u'pretty_xml'], u'json': [u'pretty_json'], u'guess': [], u'brute': [u'pretty_xml', u'pretty_json']}¶Dict that maps text_type
to a list of functions to try to pretty text
with.
tanium_kit.pretty.
pretty_text
(text, name=u'text', text_type=u'guess', **kwargs)[source]¶Try to pretty text
as text_type
.
Notes
TEXT_TYPE_MAP
, text is returned unchanged.Parameters: | |
---|---|
Returns: | text –
|
Return type: |
Pytan Extensions.
tanium_kit.pytanx.
LOG
= <logging.Logger object>¶Usage – user_obj = get_user_obj(handler, taniumpy) check_allowed_roles(user_obj=user_obj, role_names=[“Question Author”]) check_required_role(user_obj=user_obj, role_name=”Administrator”)
tanium_kit.pytanx.
check_allowed_roles
(user_obj, role_names=[])[source]¶Validate that the roles for user are in role_names.
tanium_kit.shell_parser.
FAIL_STR
= (u'no', u'n', u'false', u'f', u'0')¶from argparse import ArgumentDefaultsHelpFormatter as ArgFormatter from argparse import RawDescriptionHelpFormatter as RawFormatter
“”“Multiple inheritance Formatter class for argparse.ArgumentParser
.
If a argparse.ArgumentParser
class uses this as it’s Formatter class, it will show
the defaults for each argument in the help output
“””
pass
tanium_kit.shell_parser.
ShellParser
(*args, **kwargs)[source]¶Bases: argparse.ArgumentParser
Dict-like object class.
tanium_kit.tools.
vignere_cipher
(text, key, inverse=False)[source]¶Vigenere Cipher
The vigenere cipher is a symmetric key cipher that operates as a group of Caesar ciphers in sequence with different rotations:
KEY == boomboombo MESSAGE == helloworld CIPHERTEXT == jvopbrfqba
Like other naive ciphers, this shouldn’t be used. It is however the most secure naive cipher. It is helpful for obfuscation to prevent shoulder surfing and casual disk scanning of passwords.
Version info.
tanium_kit.wequests.
Wequests
(**kwargs)[source]¶Bases: object
DEFAULTS
= {u'files': None, u'cookies': None, u'connect_secs': 5, u'stream': None, u'https_proxy': u'', u'verify': False, u'http_proxy': u'', u'json': None, u'proxies': {}, u'auth_failures': [401, 403], u'headers': {}, u'cert': None, u'params': None, u'hooks': None, u'allow_redirects': True, u'response_secs': 15, u'data': None, u'method': u'get'}¶KWARGS
= {}¶LOUD
= True¶REQUESTS_PKG
= None¶USE_SESSION
= True¶_RS
= None¶tanium_kit.wequests.
WequestsError
[source]¶Bases: exceptions.Exception
A regex based XML cleaner that will replace unsupported characters.
tanium_kit.xml_cleaner.
DEFAULT_ENCODING
= u'utf-8'¶The default encoding to use if none supplied
tanium_kit.xml_cleaner.
DEFAULT_REPLACEMENT
= u'\ufffd'¶The default character to use when replacing characters
tanium_kit.xml_cleaner.
INVALID_UNICODE_RAW_RE
= u'[^\t\n\r -\ud7ff\ue000-\ufffd]'¶The raw regex string to use when replacing invalid characters
tanium_kit.xml_cleaner.
INVALID_UNICODE_RE
= <_sre.SRE_Pattern object>¶The regex object to use when replacing invalid characters
tanium_kit.xml_cleaner.
QUOTES_MAP
= {u'\u2019': u"'", u'\u2018': u"'", u'\u201d': u'"', u'\u201c': u'"'}¶Mapping of smart quotes to replace with their ascii counterpart.
tanium_kit.xml_cleaner.
RESTRICT_UNICODE_RAW_RE
= u'[\x7f-\x84\x86-\x9f\ufdd0-\ufdef]'¶The raw regex string to use when replacing restricted characters
tanium_kit.xml_cleaner.
RESTRICT_UNICODE_RE
= <_sre.SRE_Pattern object>¶The regex object to use when replacing restricted characters
tanium_kit.xml_cleaner.
XML_1_0_RESTRICT_HEX
= [[127, 132], [134, 159], [64976, 65007]]¶tanium_kit.xml_cleaner.
XML_1_0_RESTRICT_UNI_LIST
= [u'\x7f-\x84', u'\x86-\x9f', u'\ufdd0-\ufdef']¶A list of restricted unicode characters
tanium_kit.xml_cleaner.
XML_1_0_RESTRICT_UNI_TEXT
= u'\x7f-\x84\x86-\x9f\ufdd0-\ufdef'¶The text string containing restricted unicode characters
tanium_kit.xml_cleaner.
XML_1_0_VALID_HEX
= [[9], [10], [13], [32, 55295], [57344, 65533]]¶tanium_kit.xml_cleaner.
XML_1_0_VALID_UNI_LIST
= [u'\t', u'\n', u'\r', u' -\ud7ff', u'\ue000-\ufffd']¶A list of valid unicode characters
tanium_kit.xml_cleaner.
XML_1_0_VALID_UNI_TEXT
= u'\t\n\r -\ud7ff\ue000-\ufffd'¶The text string containing valid unicode characters
tanium_kit.zipper.
ZIP_ADD
()¶S.format(*args, **kwargs) -> unicode
Return a formatted version of S, using substitutions from args and kwargs. The substitutions are identified by braces (‘{‘ and ‘}’).
tanium_kit.zipper.
ZIP_MAKE
()¶S.format(*args, **kwargs) -> unicode
Return a formatted version of S, using substitutions from args and kwargs. The substitutions are identified by braces (‘{‘ and ‘}’).
tanium_kit.zipper.
ZIP_PATTERNS
()¶S.format(*args, **kwargs) -> unicode
Return a formatted version of S, using substitutions from args and kwargs. The substitutions are identified by braces (‘{‘ and ‘}’).