diff --git a/Changelog b/Changelog new file mode 100644 index 0000000..8fa7ae7 --- /dev/null +++ b/Changelog @@ -0,0 +1,2 @@ +TellMe (1.2.0) + * Feature complete version diff --git a/control b/control deleted file mode 100644 index 8d973f9..0000000 --- a/control +++ /dev/null @@ -1,6 +0,0 @@ -Package: telme -Version: 1.0.1 -Maintainer: Guy Van Sanden -Architecture: all -Depends: python -Description: TellMe CLI diff --git a/package.json b/package.json index 76684b0..2a034ce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "TellMe", - "version": "1.0.1", + "version": "1.2.0", "description": "TellMe CLI", "scripts": { "dev": "webpack-dev-server --inline --hot" diff --git a/src/tellme.py b/src/tellme.py index c6585b1..c95c8f7 100755 --- a/src/tellme.py +++ b/src/tellme.py @@ -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)