2

Is there any way available to check the status of a apache tomcat server from another machine in python?

For example, A restful API is running in a machine with apache tomcat server in 8086 port.

enter image description here

Now, what I want is to check the status of the apache tomcat service of the specified machine from my pc programmatically in python.

Yes,I could check the machine is running or not through pinging by using os.system in python.

import os
hostname = "xxx.xxx.xxx.xxx" #example
response = os.system("ping -c 1 " + hostname)

#and then check the response...
if response == 0:
    print hostname, 'is up!'
else:
    print hostname, 'is down!'

But, what I am interested in is that, is it possible to check the status of the service (real_ip:8086/BotAPI) in stead of the liveness of the machine, programmatically in python ?

Update: using paramiko I got the following traceback

channel.exec_command('ps -ef| grep tomcat')
Traceback (most recent call last):
File "<pyshell#67>", line 1, in <module>
channel.exec_command('ps -ef| grep tomcat')
File "E:\python\lib\site-packages\paramiko\channel.py", line 63, in _check
return func(self, *args, **kwds)
File "E:\python\lib\site-packages\paramiko\channel.py", line 241, in exec_command
self._wait_for_event()
File "E:\python\lib\site-packages\paramiko\channel.py", line 1197, in _wait_for_event
raise e
paramiko.ssh_exception.SSHException: Channel closed.
S.Rakin
  • 698
  • 9
  • 21

1 Answers1

1

You could use fabric or paramiko to connect remotely to your tomcat machine and then check if the process is running

import paramiko

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('hostname', username='user', password='password')

transport = ssh.get_transport()
channel = transport.open_session()
channel.exec_command('ps -ef | grep tomcat')

status = channel.recv_exit_status()
lapinkoira
  • 6,688
  • 7
  • 36
  • 74