Added changelog

Added ping
This commit is contained in:
Guy Van Sanden 2023-05-16 16:34:59 +02:00
parent c01248f628
commit f9d1c49e19
4 changed files with 42 additions and 18 deletions

2
Changelog Normal file
View File

@ -0,0 +1,2 @@
TellMe (1.2.0)
* Feature complete version

View File

@ -1,6 +0,0 @@
Package: telme
Version: 1.0.1
Maintainer: Guy Van Sanden <guy@taurix.net>
Architecture: all
Depends: python
Description: TellMe CLI

View File

@ -1,6 +1,6 @@
{
"name": "TellMe",
"version": "1.0.1",
"version": "1.2.0",
"description": "TellMe CLI",
"scripts": {
"dev": "webpack-dev-server --inline --hot"

View File

@ -19,6 +19,7 @@ def signal_handler(signal, frame):
sys.exit(0)
def sendmessage (message):
global ran
# mymessage=hostname.upper() + ': ' +message
mymessage = ("%s on %s" % (message, hostname.upper()))
@ -32,11 +33,14 @@ def sendmessage (message):
r = requests.post(url, json = { 'message': mymessage, 'tts': args.tts })
if r.status_code == 200:
print("Message has been sent successfully")
# print(message)
else:
print("Message sending FAILED")
ran = True
__version__ = "1.0.1"
__version__ = "1.2.0"
versionstring='TellMe v' + __version__
signal.signal(signal.SIGINT, signal_handler)
@ -52,6 +56,7 @@ parser.add_argument('-p', '--pid', action="store", dest="pid", type=int, default
parser.add_argument('-n', '--interval', action="store", dest="interval", type=int, default=5, help="Set the interval of commands like watch that use it")
parser.add_argument('-w', '--watch', action="store", dest="watchcommand", help="Run the given command every n or 5 minutes")
parser.add_argument('-c', '--config', default=home +"/.config/tellme/config.json" ,help="Path to config file")
parser.add_argument('-P', '--ping', action="store", dest="pinghost", type=str, help="Ping a host until it is up")
#print parser.parse_args()
args = parser.parse_args()
@ -69,19 +74,42 @@ baseurl = config['url']
webhook = config['webhook']
message = args.message
ran = False
if args.pid != 0:
path = "/proc/%i" %(args.pid)
print("Monitoring process %i" %(args.pid))
while os.path.exists(path):
time.sleep(10)
sendmessage(message)
else:
if(args.watchcommand):
print("Watching %s every %i minutes" %(args.watchcommand,int(args.interval)))
while True:
output = subprocess.Popen(args.watchcommand, shell=True, stdout=subprocess.PIPE).stdout.read()
print(output)
sendmessage("|%s|" %(output))
time.sleep(60*int(args.interval))
else:
sendmessage(message)
if(args.watchcommand):
print("Watching %s every %i minutes" %(args.watchcommand,int(args.interval)))
while True:
output = subprocess.Popen(args.watchcommand, shell=True, stdout=subprocess.PIPE).stdout.read()
print(output)
sendmessage("|%s|" %(output))
time.sleep(60*int(args.interval))
if(args.pinghost):
print("Pinging %s" %(args.pinghost))
response = None
while response != 0:
response = os.system("ping -c 1 -w 1 %s >/dev/null" % (args.pinghost))
if response == 0:
print("Up")
sendmessage("Host %s is Up" % (args.pinghost))
else:
print("Down")
if args.interval:
interval = args.interval
else:
interval = 60
time.sleep(int(args.interval))
if ran is False:
sendmessage(message)