bug fix: query as filters and console support

master
Steve Nyemba 1 week ago
parent 57a97e8df1
commit 700452c8de

@ -31,7 +31,7 @@ import plugin_ix
# iregistry = plugins.Registry(meta.__home__)
@_cli.command(name='log-intruder')
def intrusion(path:str='/var/log/auth.log', year:int=datetime.now().year):
def intrusion(path:str='/var/log/auth.log', year:int=datetime.now().year,debug:bool=False):
"""
This function
"""
@ -42,8 +42,10 @@ def intrusion(path:str='/var/log/auth.log', year:int=datetime.now().year):
try:
_pointer = getattr(smart.logger,_id)
_df = _pointer(_r[_id])
post(_df,_id)
if debug :
print (_df)
else:
post(_df,_id)
except Exception as e:
print (e)
pass
@ -52,18 +54,21 @@ def intrusion(path:str='/var/log/auth.log', year:int=datetime.now().year):
print ("Nothing out of the ordinary was found in")
print (f"{path}")
@_cli.command(name='top')
def apply_apps (app:str=None,user:str=None):
def apply_apps (app:str=None,user:str=None,debug:bool=False):
"""
This function looks at applications/commands running on the system
"""
_df = smart.top.read(name=app)
_df = smart.top.read(name=app,user=user)
_id = 'apps' if not app else app
# if app :
# _index = _df.name == app
# if _index.sum() :
# _df = _df[_index]
post(_df,_id)
if debug :
print (_df)
else:
post(_df,_id)
@_cli.command(name='archive')
def _archive():
@ -86,18 +91,24 @@ def _archive():
"""
print(_msg)
@_cli.command(name='folder')
def apply_folder(path:str):
def apply_folder(path:str,debug:bool=False):
"""
This function will read the content of a folder and generate a
"""
_df = smart.folder.read(path=path)
# print (_df)
post(_df,'folders')
if debug :
print(_df)
else:
post(_df,'folders')
pass
@_cli.command (name='files')
def apply_files(folder:str) :
def apply_files(folder:str,debug:bool=False) :
_df = smart.files.read(folder)
post(_df,'files')
if debug:
print(_df)
else:
post(_df,'files')
@_cli.command(name='init')
# @plugins.cli.appr(name='init')
def apply_signup (email:str,key:str=None,provider:str='sqlite') :
@ -120,7 +131,7 @@ def apply_signup (email:str,key:str=None,provider:str='sqlite') :
else:
_verb = "updated"
f = open(os.sep.join([_PATH,'config.json']),'w')
f.write(json.dumps(_config))
f.write(json.dumps(_config,indent=2))
f.close()
_msg = f"""
The configuration file was {_verb} successfully at {meta.__home__}

@ -1,6 +1,6 @@
import os
__app_name__= "smart-logger"
__version__ = "1.12"
__version__ = "1.14"
__author__ = "Steve L. Nyemba, info@the-phi.com"
__home__ = os.sep.join([os.environ['HOME'],'.smart-logger'])
__database__='smart_logs'

@ -89,25 +89,32 @@ def read(**args) :
# @TODO: Add filter here to handle filter on different columns
#
if 'name' in args and args['name']:
names = args['name'].split(',')
r = pd.DataFrame()
for name in names :
# tmp = df[df.name == name.strip() ]
# ii = df.apply(lambda row: row['name'] == name.strip() or (name.strip() in str(row['name'])),axis=1).tolist()
ii = df.apply(lambda row: type(row['cmd']) ==str and name.strip() == row['name'] in row['cmd'],axis=1).tolist()
tmp= df[ii]
# tmp.index = np.arange(tmp.shape[0])
if tmp.empty:
tmp = {"pid":None,"user":None,"mem":0,"cpu":0,"status":"-100","started":None,"name":name,"cmd":None,"args":None,"date":d,"time":t,"node":n}
# if 'name' in args and args['name']:
# names = args['name'].split(',')
# r = pd.DataFrame()
# for name in names :
# # tmp = df[df.name == name.strip() ]
# # ii = df.apply(lambda row: row['name'] == name.strip() or (name.strip() in str(row['name'])),axis=1).tolist()
# ii = df.apply(lambda row: type(row['cmd']) ==str and name.strip() == row['name'] in row['cmd'],axis=1).tolist()
# tmp= df[ii]
# # tmp.index = np.arange(tmp.shape[0])
# if tmp.empty:
# tmp = {"pid":None,"user":None,"mem":0,"cpu":0,"status":"-100","started":None,"name":name,"cmd":None,"args":None,"date":d,"time":t,"node":n}
else:
#r = r.append(tmp,ignore_index=False)
r = pd.concat([r, tmp]) #r.append(tmp,ignore_index=False)
if not r.empty :
# r.index = np.arange(r.shape[0])
df = r.copy()
# else:
# #r = r.append(tmp,ignore_index=False)
# r = pd.concat([r, tmp]) #r.append(tmp,ignore_index=False)
# if not r.empty :
# # r.index = np.arange(r.shape[0])
# df = r.copy()
if 'name' in args and args['name'] :
_names = ",".join([ f"'{_name.strip()}'"for _name in args['name'].split(",")])
df = df.query(f"name in ({_names})")
if 'user' in args and args['user'] :
_users = ",".join([ f"'{_name.strip()}'"for _name in args['user'].split(",")])
df = df.query(f"user in ({_users})")
#
# For security reasons lets has the args columns with an MD5 or sha256
#

Loading…
Cancel
Save