Skip to content

Commit bb5027d

Browse files
authored
Merge pull request #733 from Tenebriso/LOG
change LOG to log everywhere
2 parents 3176111 + a8d9273 commit bb5027d

20 files changed

+240
-240
lines changed

hubblestack/extmods/audit/grep.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
from salt.exceptions import CommandExecutionError
5252

53-
LOG = logging.getLogger(__name__)
53+
log = logging.getLogger(__name__)
5454

5555

5656
def grep(path,

hubblestack/extmods/fdg/curl.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import requests
1919

2020

21-
LOG = logging.getLogger(__name__)
21+
log = logging.getLogger(__name__)
2222

2323

2424
def request(url,
@@ -99,7 +99,7 @@ def request(url,
9999
Ignored
100100
"""
101101
if chained:
102-
LOG.warn('Chained value detected in curl.request module. Chained '
102+
log.warn('Chained value detected in curl.request module. Chained '
103103
'values are unsupported in the curl fdg module.')
104104

105105
# Data validation and preparation
@@ -116,7 +116,7 @@ def request(url,
116116
kwargs['headers'] = headers
117117
kwargs['timeout'] = int(timeout)
118118
if function not in ('GET', 'PUT', 'POST'):
119-
LOG.error('Invalid request type %s', function)
119+
log.error('Invalid request type %s', function)
120120
return False, {}
121121

122122
# Make the request

hubblestack/extmods/fdg/grep.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from salt.exceptions import CommandExecutionError
1313

14-
LOG = logging.getLogger(__name__)
14+
log = logging.getLogger(__name__)
1515

1616

1717
def file(path, pattern, grep_args=None, format_chained=True, chained=None, chained_status=None):

hubblestack/extmods/fdg/osquery.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import os
1212

1313

14-
LOG = logging.getLogger(__name__)
14+
log = logging.getLogger(__name__)
1515

1616

1717
def query(query_sql, osquery_args=None, osquery_path=None,
@@ -67,19 +67,19 @@ def _osquery(query_sql, osquery_path=None, args=None):
6767
if not query_sql:
6868
return False, ''
6969
if 'attach' in query_sql.lower() or 'curl' in query_sql.lower():
70-
LOG.critical('Skipping potentially malicious osquery query \'%s\' '
70+
log.critical('Skipping potentially malicious osquery query \'%s\' '
7171
'which contains either \'attach\' or \'curl\'', query_sql)
7272
return False, ''
7373

7474
# Prep the command
7575
if not osquery_path:
7676
if not os.path.isfile(__grains__['osquerybinpath']):
77-
LOG.error('osquery binary not found: %s', __grains__['osquerybinpath'])
77+
log.error('osquery binary not found: %s', __grains__['osquerybinpath'])
7878
return False, ''
7979
cmd = [__grains__['osquerybinpath'], '--read_max', max_file_size, '--json', query_sql]
8080
else:
8181
if not os.path.isfile(osquery_path):
82-
LOG.error('osquery binary not found: %s', osquery_path)
82+
log.error('osquery binary not found: %s', osquery_path)
8383
return False, ''
8484
cmd = [osquery_path, '--read_max', max_file_size, '--json', query_sql]
8585
if isinstance(args, (list,tuple)):

hubblestack/extmods/fdg/process.py

+28-28
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from hubblestack.utils.encoding import encode_base64 as utils_encode_base64
1515
from salt.exceptions import ArgumentValueError
1616

17-
LOG = logging.getLogger(__name__)
17+
log = logging.getLogger(__name__)
1818

1919

2020
def filter_dict(starting_dict=None, filter_values=False, update_chained=True,
@@ -42,7 +42,7 @@ def filter_dict(starting_dict=None, filter_values=False, update_chained=True,
4242
if starting_dict:
4343
chained.update(starting_dict)
4444
except (AttributeError, TypeError, ValueError):
45-
LOG.error('Invalid argument type - dict required', exc_info=True)
45+
log.error('Invalid argument type - dict required', exc_info=True)
4646
return False, None
4747
ret = _filter_dict(chained, filter_values, kwargs)
4848
status = bool(ret)
@@ -105,7 +105,7 @@ def _compare(comp, val1, val2):
105105
if comp == "ne":
106106
return val1 != val2
107107

108-
LOG.error("Invalid argument '%s' - should be in [gt, ge, lt, le, eq, ne]", comp)
108+
log.error("Invalid argument '%s' - should be in [gt, ge, lt, le, eq, ne]", comp)
109109
raise ArgumentValueError
110110

111111

@@ -147,7 +147,7 @@ def filter_seq(starting_seq=None, extend_chained=True, chained=None, chained_sta
147147
else:
148148
raise AttributeError
149149
except (AttributeError, TypeError, ValueError):
150-
LOG.error("Invalid argument type", exc_info=True)
150+
log.error("Invalid argument type", exc_info=True)
151151
return False, None
152152
ret = _filter(seq=chained, filter_rules=kwargs)
153153
status = bool(ret)
@@ -171,7 +171,7 @@ def _filter(seq,
171171
not equal to 2.
172172
"""
173173
if not isinstance(filter_rules, dict):
174-
LOG.error("``filter_rules`` should be of type dict")
174+
log.error("``filter_rules`` should be of type dict")
175175
return None
176176
ret = seq
177177
for comp, value in filter_rules.iteritems():
@@ -205,15 +205,15 @@ def get_index(index=0, starting_list=None, extend_chained=True, chained=None, ch
205205
try:
206206
chained.extend(starting_list)
207207
except (AttributeError, TypeError):
208-
LOG.error("Invalid argument type", exc_info=True)
208+
log.error("Invalid argument type", exc_info=True)
209209
return False, None
210210
try:
211211
ret = chained[index]
212212
except IndexError:
213-
LOG.error('List index out of range %d', index, exc_info=True)
213+
log.error('List index out of range %d', index, exc_info=True)
214214
return False, None
215215
except TypeError:
216-
LOG.error('Arguments should be of type list', exc_info=True)
216+
log.error('Arguments should be of type list', exc_info=True)
217217
return False, None
218218
status = bool(ret)
219219

@@ -240,15 +240,15 @@ def get_key(key, starting_dict=None, update_chained=True, chained=None, chained_
240240
try:
241241
chained.update(starting_dict)
242242
except (TypeError, ValueError):
243-
LOG.error("Arguments should be of type dict.", exc_info=True)
243+
log.error("Arguments should be of type dict.", exc_info=True)
244244
return False, None
245245
try:
246246
ret = chained[key]
247247
except KeyError:
248-
LOG.error("Key not found: %s", key, exc_info=True)
248+
log.error("Key not found: %s", key, exc_info=True)
249249
return False, None
250250
except TypeError:
251-
LOG.error("Arguments should be of type dict.", exc_info=True)
251+
log.error("Arguments should be of type dict.", exc_info=True)
252252
return False, None
253253
status = bool(ret)
254254

@@ -277,12 +277,12 @@ def join(words=None, sep='', extend_chained=True, chained=None, chained_status=N
277277
try:
278278
chained.extend(words)
279279
except (AttributeError, TypeError):
280-
LOG.error("Arguments should be of type list.", exc_info=True)
280+
log.error("Arguments should be of type list.", exc_info=True)
281281
return False, None
282282
try:
283283
ret = sep.join(chained)
284284
except (TypeError, AttributeError):
285-
LOG.error("Invalid arguments type.", exc_info=True)
285+
log.error("Invalid arguments type.", exc_info=True)
286286
ret = None
287287
status = bool(ret)
288288

@@ -313,7 +313,7 @@ def sort(seq=None, desc=False, lexico=False, extend_chained=True,
313313
elif seq and isinstance(chained, str):
314314
chained = seq.format(chained)
315315
except (AttributeError, TypeError, ValueError):
316-
LOG.error("Invalid arguments type.", exc_info=True)
316+
log.error("Invalid arguments type.", exc_info=True)
317317
return False, None
318318
ret = _sort(chained, desc, lexico)
319319
status = bool(ret)
@@ -342,7 +342,7 @@ def _sort(seq,
342342
try:
343343
ret = sorted(seq, reverse=desc, key=key)
344344
except TypeError:
345-
LOG.error("Invalid argument type.", exc_info=True)
345+
log.error("Invalid argument type.", exc_info=True)
346346
return None
347347

348348
return ret
@@ -371,7 +371,7 @@ def split(phrase, sep=None, regex=False, format_chained=True, chained=None, chai
371371
try:
372372
phrase = phrase.format(chained)
373373
except AttributeError:
374-
LOG.error("Invalid attributes type.", exc_info=True)
374+
log.error("Invalid attributes type.", exc_info=True)
375375
return False, None
376376
ret = _split(phrase, sep, regex)
377377
status = bool(ret) and len(ret) > 1
@@ -401,7 +401,7 @@ def _split(phrase,
401401
else:
402402
ret = phrase.split(sep)
403403
except (AttributeError, TypeError):
404-
LOG.error("Invalid argument type.", exc_info=True)
404+
log.error("Invalid argument type.", exc_info=True)
405405
return None
406406

407407
return ret
@@ -426,7 +426,7 @@ def dict_to_list(starting_dict=None, update_chained=True, chained=None, chained_
426426
try:
427427
chained.update(starting_dict)
428428
except (AttributeError, ValueError, TypeError):
429-
LOG.error("Invalid arguments type.", exc_info=True)
429+
log.error("Invalid arguments type.", exc_info=True)
430430
return False, None
431431
ret = [(key, value) for key, value in chained.iteritems()]
432432
status = bool(ret)
@@ -456,14 +456,14 @@ def dict_convert_none(starting_seq=None, extend_chained=True, chained=None, chai
456456
elif starting_seq and isinstance(chained, list):
457457
chained.extend(starting_seq)
458458
except (AttributeError, TypeError, ValueError):
459-
LOG.error("Invalid type of arguments", exc_info=True)
459+
log.error("Invalid type of arguments", exc_info=True)
460460
return False, None
461461
if isinstance(chained, dict):
462462
ret = _dict_convert_none(chained)
463463
elif isinstance(chained, (set, list, tuple)):
464464
ret = _seq_convert_none(chained)
465465
else:
466-
LOG.error("Invalid arguments type - dict or sequence expected")
466+
log.error("Invalid arguments type - dict or sequence expected")
467467
ret = None
468468
status = bool(ret)
469469

@@ -479,7 +479,7 @@ def _dict_convert_none(dictionary):
479479
The input dict to sterilize
480480
"""
481481
if not isinstance(dictionary, dict):
482-
LOG.error("Invalid argument type - should be dict")
482+
log.error("Invalid argument type - should be dict")
483483
return None
484484
updated_dict = {}
485485
for key, value in dictionary.iteritems():
@@ -505,7 +505,7 @@ def _seq_convert_none(seq):
505505
The input sequence to sterilize
506506
"""
507507
if not isinstance(seq, (list, set, tuple)):
508-
LOG.error("Invalid argument type - list set or tuple expected")
508+
log.error("Invalid argument type - list set or tuple expected")
509509
return None
510510
updated_seq = []
511511
for element in seq:
@@ -537,10 +537,10 @@ def print_string(starting_string, format_chained=True, chained=None, chained_sta
537537
try:
538538
starting_string = starting_string.format(chained)
539539
except AttributeError:
540-
LOG.error("Invalid type for starting_string - has to be string.", exc_info=True)
540+
log.error("Invalid type for starting_string - has to be string.", exc_info=True)
541541
return False, None
542542
if not isinstance(starting_string, str):
543-
LOG.error('Invalid arguments - starting_string should be a string')
543+
log.error('Invalid arguments - starting_string should be a string')
544544
return False, None
545545

546546
return bool(starting_string), starting_string
@@ -568,14 +568,14 @@ def dict_remove_none(starting_seq=None, extend_chained=True, chained=None, chain
568568
elif starting_seq and isinstance(chained, list):
569569
chained.extend(starting_seq)
570570
except (AttributeError, TypeError, ValueError):
571-
LOG.error("Invalid arguments type", exc_info=True)
571+
log.error("Invalid arguments type", exc_info=True)
572572
return False, None
573573
if isinstance(chained, dict):
574574
ret = _sterilize_dict(chained)
575575
elif isinstance(chained, (list, set, tuple)):
576576
ret = _sterilize_seq(chained)
577577
else:
578-
LOG.error("Invalid arguments type - dict, list, set or tuple expected")
578+
log.error("Invalid arguments type - dict, list, set or tuple expected")
579579
ret = None
580580
status = bool(ret)
581581

@@ -591,7 +591,7 @@ def _sterilize_dict(dictionary):
591591
The input dict to sterilize
592592
"""
593593
if not isinstance(dictionary, dict):
594-
LOG.error("Invalid argument type - should be dict")
594+
log.error("Invalid argument type - should be dict")
595595
return None
596596
updated_dict = {}
597597
for key, value in dictionary.iteritems():
@@ -614,7 +614,7 @@ def _sterilize_seq(seq):
614614
The input sequence to sterilize
615615
"""
616616
if not isinstance(seq, (list, set, tuple)):
617-
LOG.error('Invalid argument type - should be list, set or tuple')
617+
log.error('Invalid argument type - should be list, set or tuple')
618618
return None
619619
updated_seq = []
620620
for element in seq:

hubblestack/extmods/fdg/process_status.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import logging
1111

1212

13-
LOG = logging.getLogger(__name__)
13+
log = logging.getLogger(__name__)
1414

1515

1616
def list_processes(chained=None, chained_status=None):
@@ -27,7 +27,7 @@ def list_processes(chained=None, chained_status=None):
2727
try:
2828
ret = _convert_to_str(res['data'])
2929
except (KeyError, TypeError):
30-
LOG.error('Invalid data type returned by osquery call %s.', res, exc_info=True)
30+
log.error('Invalid data type returned by osquery call %s.', res, exc_info=True)
3131
return False, None
3232

3333
return bool(ret), ret
@@ -48,7 +48,7 @@ def _convert_to_str(process_data):
4848
str_process = {str(name): str(val) for name, val in process.iteritems()}
4949
ret.append(str_process)
5050
except (TypeError, AttributeError):
51-
LOG.error('Invalid argument type; must be list of dicts.', exc_info=True)
51+
log.error('Invalid argument type; must be list of dicts.', exc_info=True)
5252
return None
5353

5454
return ret
@@ -64,10 +64,10 @@ def _run_query(query_sql):
6464
res = __salt__['nebula.query'](query_sql)
6565
try:
6666
if not res['result']:
67-
LOG.error("Error executing the osquery query: %s", res['error'])
67+
log.error("Error executing the osquery query: %s", res['error'])
6868
return None
6969
except (KeyError, TypeError):
70-
LOG.error('Invalid data type returned by osquery call %s.', res, exc_info=True)
70+
log.error('Invalid data type returned by osquery call %s.', res, exc_info=True)
7171
return None
7272

7373
return res
@@ -115,7 +115,7 @@ def find_process(filter_sql, fields=None, format_chained=True, chained=None, cha
115115
try:
116116
filter_sql = filter_sql.format(chained)
117117
except (AttributeError, TypeError):
118-
LOG.error("Invalid arguments.", exc_info=True)
118+
log.error("Invalid arguments.", exc_info=True)
119119
# default fields to `name` and `PID`
120120
if fields:
121121
fields += ',name,pid'
@@ -126,7 +126,7 @@ def find_process(filter_sql, fields=None, format_chained=True, chained=None, cha
126126
try:
127127
ret = _convert_to_str(res['data'])
128128
except (KeyError, TypeError):
129-
LOG.error('Invalid data type returned by osquery call %s.', res, exc_info=True)
129+
log.error('Invalid data type returned by osquery call %s.', res, exc_info=True)
130130
return False, None
131131

132132
return bool(ret), ret
@@ -158,14 +158,14 @@ def is_running(filter_sql, format_chained=True, chained=None, chained_status=Non
158158
try:
159159
filter_sql = filter_sql.format(chained)
160160
except (AttributeError, TypeError):
161-
LOG.error('Invalid arguments.', exc_info=True)
161+
log.error('Invalid arguments.', exc_info=True)
162162
query = 'SELECT state FROM processes where {0}'.format(filter_sql)
163163
res = _run_query(query)
164164
if not res:
165165
return False, None
166166
# more than one process
167167
if len(res['data']) > 1:
168-
LOG.error('Search outputs %d results. Should output only 1', len(res['data']))
168+
log.error('Search outputs %d results. Should output only 1', len(res['data']))
169169
return False, None
170170
# no processses matched the search
171171
if not res['data']:
@@ -209,7 +209,7 @@ def find_children(parent_filter, parent_field=None, returned_fields=None,
209209
try:
210210
parent_filter = parent_filter.format(chained)
211211
except (AttributeError, TypeError):
212-
LOG.error('Invalid arguments.', exc_info=True)
212+
log.error('Invalid arguments.', exc_info=True)
213213
return False, None
214214
# default returned_fields to `name` and `PID`
215215
if returned_fields:
@@ -226,7 +226,7 @@ def find_children(parent_filter, parent_field=None, returned_fields=None,
226226
try:
227227
ret = _convert_to_str(res['data'])
228228
except (KeyError, TypeError):
229-
LOG.error('Invalid data type returned by osquery call %s.', res, exc_info=True)
229+
log.error('Invalid data type returned by osquery call %s.', res, exc_info=True)
230230
return False, None
231231

232232
return bool(ret), ret

0 commit comments

Comments
 (0)