Added changelog
Added ping
This commit is contained in:
parent
c01248f628
commit
f9d1c49e19
6
control
6
control
@ -1,6 +0,0 @@
|
|||||||
Package: telme
|
|
||||||
Version: 1.0.1
|
|
||||||
Maintainer: Guy Van Sanden <guy@taurix.net>
|
|
||||||
Architecture: all
|
|
||||||
Depends: python
|
|
||||||
Description: TellMe CLI
|
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "TellMe",
|
"name": "TellMe",
|
||||||
"version": "1.0.1",
|
"version": "1.2.0",
|
||||||
"description": "TellMe CLI",
|
"description": "TellMe CLI",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "webpack-dev-server --inline --hot"
|
"dev": "webpack-dev-server --inline --hot"
|
||||||
|
@ -19,6 +19,7 @@ def signal_handler(signal, frame):
|
|||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
def sendmessage (message):
|
def sendmessage (message):
|
||||||
|
global ran
|
||||||
# mymessage=hostname.upper() + ': ' +message
|
# mymessage=hostname.upper() + ': ' +message
|
||||||
mymessage = ("%s on %s" % (message, hostname.upper()))
|
mymessage = ("%s on %s" % (message, hostname.upper()))
|
||||||
|
|
||||||
@ -32,11 +33,14 @@ def sendmessage (message):
|
|||||||
r = requests.post(url, json = { 'message': mymessage, 'tts': args.tts })
|
r = requests.post(url, json = { 'message': mymessage, 'tts': args.tts })
|
||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
print("Message has been sent successfully")
|
print("Message has been sent successfully")
|
||||||
|
# print(message)
|
||||||
else:
|
else:
|
||||||
print("Message sending FAILED")
|
print("Message sending FAILED")
|
||||||
|
|
||||||
|
ran = True
|
||||||
|
|
||||||
__version__ = "1.0.1"
|
|
||||||
|
__version__ = "1.2.0"
|
||||||
versionstring='TellMe v' + __version__
|
versionstring='TellMe v' + __version__
|
||||||
|
|
||||||
signal.signal(signal.SIGINT, signal_handler)
|
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('-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('-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('-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()
|
#print parser.parse_args()
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@ -69,19 +74,42 @@ baseurl = config['url']
|
|||||||
webhook = config['webhook']
|
webhook = config['webhook']
|
||||||
|
|
||||||
message = args.message
|
message = args.message
|
||||||
|
ran = False
|
||||||
|
|
||||||
if args.pid != 0:
|
if args.pid != 0:
|
||||||
path = "/proc/%i" %(args.pid)
|
path = "/proc/%i" %(args.pid)
|
||||||
print("Monitoring process %i" %(args.pid))
|
print("Monitoring process %i" %(args.pid))
|
||||||
while os.path.exists(path):
|
while os.path.exists(path):
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|
||||||
sendmessage(message)
|
sendmessage(message)
|
||||||
else:
|
|
||||||
if(args.watchcommand):
|
if(args.watchcommand):
|
||||||
print("Watching %s every %i minutes" %(args.watchcommand,int(args.interval)))
|
print("Watching %s every %i minutes" %(args.watchcommand,int(args.interval)))
|
||||||
while True:
|
while True:
|
||||||
output = subprocess.Popen(args.watchcommand, shell=True, stdout=subprocess.PIPE).stdout.read()
|
output = subprocess.Popen(args.watchcommand, shell=True, stdout=subprocess.PIPE).stdout.read()
|
||||||
print(output)
|
print(output)
|
||||||
sendmessage("|%s|" %(output))
|
sendmessage("|%s|" %(output))
|
||||||
time.sleep(60*int(args.interval))
|
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:
|
else:
|
||||||
|
print("Down")
|
||||||
|
|
||||||
|
if args.interval:
|
||||||
|
interval = args.interval
|
||||||
|
else:
|
||||||
|
interval = 60
|
||||||
|
|
||||||
|
time.sleep(int(args.interval))
|
||||||
|
|
||||||
|
if ran is False:
|
||||||
sendmessage(message)
|
sendmessage(message)
|
||||||
|
Loading…
Reference in New Issue
Block a user