parent
b063852f6d
commit
5834a10099
@ -0,0 +1 @@
|
||||
__init__.py
|
@ -1,15 +0,0 @@
|
||||
"""
|
||||
This file will submit an alert to either a mailbox given a set of parameters, this will perform as following :
|
||||
- as-a-service
|
||||
- embedded
|
||||
"""
|
||||
|
||||
check = None
|
||||
def post(**args):
|
||||
"""
|
||||
This function will submit a report to a given target provided some input
|
||||
:key will perform as-a-service
|
||||
:data data that will be submitted to smtp/queue server
|
||||
:smtp will send the file to a mailbox
|
||||
"""
|
||||
pass
|
@ -0,0 +1,65 @@
|
||||
"""
|
||||
This file will submit an alert to either a mailbox given a set of parameters, this will perform as following :
|
||||
- as-a-service
|
||||
- embedded
|
||||
"""
|
||||
import os
|
||||
import pandas as pd
|
||||
import subprocess
|
||||
import glob
|
||||
from datetime import datetime
|
||||
|
||||
def post(**args):
|
||||
"""
|
||||
This function will submit a report to a given target provided some input
|
||||
:key will perform as-a-service
|
||||
:data data that will be submitted to smtp/queue server
|
||||
:smtp will send the file to a mailbox
|
||||
"""
|
||||
pass
|
||||
def parse(_stream):
|
||||
"""
|
||||
:stream single from the output command that has been executed
|
||||
"""
|
||||
_blocks = _stream.replace(' ',' ').split(' ')
|
||||
if len(_blocks) > 6 :
|
||||
_user = _blocks[1]
|
||||
_group= _blocks[2]
|
||||
_size = _blocks[3] # if units are not specified please interpet this as bytes
|
||||
_date = "-".join(_blocks[4:6])
|
||||
_time = _blocks[6]
|
||||
_name = _blocks[-1]
|
||||
if ':' not in _time :
|
||||
_date = _date+' '+_time
|
||||
_time = '00:00'
|
||||
else:
|
||||
_date = _date+'-'+str(datetime.now().year)
|
||||
_name = _blocks[-1]
|
||||
return {'user':_user,'date':_date,'time':_time,'size':_size,'content':None,'name':_name}
|
||||
def apply(_cmd, parser=None):
|
||||
handler = subprocess.Popen(_cmd,shell=True,stdout=subprocess.PIPE,encoding='utf-8')
|
||||
stream = handler.communicate()[0].split('\n')
|
||||
stream = [line.strip() for line in stream]
|
||||
if not parser :
|
||||
# print (dict(zip(['hash','names'],stream[0].split())))
|
||||
|
||||
stream = [ line.strip().replace(' ',' ').split(' ') for line in stream if len(line.strip().split()) == 2]
|
||||
return pd.DataFrame([dict(zip(['content','name'],line)) for line in stream])
|
||||
# return pd.DataFrame([ line.split() for line in stream ])
|
||||
|
||||
# return pd.DataFrame( dict(zip(['checksum','name'],[line.strip().split(' '))) for line in stream if line.strip() != '']) )
|
||||
else:
|
||||
return pd.DataFrame([ parser(line.strip()) for line in stream if line.strip() != ''])
|
||||
def read (path):
|
||||
"""
|
||||
This function will read files in a folder and provide has expressions of the files
|
||||
"""
|
||||
_cmd = ["""find :path -type f -exec md5sum "{}" + """ , """find :path -type f -exec ls -lh "{}" + |grep -E " .*$" -o """]
|
||||
_df = apply(_cmd[0].replace(":path",path))
|
||||
_data= apply(_cmd[1].replace(":path",path),parse)
|
||||
if _data.shape[0] == _df.shape[0] :
|
||||
_data['content'] = _df.content
|
||||
return _data
|
||||
|
||||
|
||||
read('/home/steve/tmp/logs')
|
@ -1,2 +1,2 @@
|
||||
import smart.folder
|
||||
print (smart.folder.read(path='/home/steve/dev/data/vumc/aou'))
|
||||
print (smart.folder.read(path='/home/steve/tmp/logs'))
|
@ -0,0 +1,15 @@
|
||||
import os
|
||||
__app_name__= "smart-logger"
|
||||
__version__ = "1.0-RC"
|
||||
__author__ = "Steve L. Nyemba, info@the-phi.com"
|
||||
__home__ = os.sep.join([os.environ['HOME'],'.smart-logger'])
|
||||
__database__='smart_logs'
|
||||
__license__= """
|
||||
Copyright 2017 - 2023, The Phi Technology
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
"""
|
Loading…
Reference in new issue