Monitoring SSHd and web servers?

Discussion in 'Python' started by Gilles Ganault, Mar 14, 2008.

  1. Hello

    I'd like to monitor connections to a remote SSH and web server. Does
    someone have some code handy that would try to connect every 5mn, and
    print an error if the script can't connect?

    Thank you.
    Gilles Ganault, Mar 14, 2008
    #1
    1. Advertising

  2. On Mar 13, 11:32 pm, Gilles Ganault <> wrote:
    > I'd like to monitor connections to a remote SSH and web server. Does
    > someone have some code handy that would try to connect every 5mn, and
    > print an error if the script can't connect?


    from time import sleep
    while True:
    # Try to connect. May want to spawn a subprocess running a simple
    shell script
    # Handle success / failure appropriately
    sleep 5*60 # Sleep for 5 minutes

    What you monitor is up to you. At a basic level, you can see if the
    server is accepting connections. At a higher level, see if you can get
    a page or see if you can login as a specific person. At a higher
    level, you may want to check what is on the page or what happens when
    you log in. It's all up to you.
    Jonathan Gardner, Mar 14, 2008
    #2
    1. Advertising

  3. Gilles Ganault

    Shane Geiger Guest

    I would recommend using a tried-and-true solution for making sure your
    uptime of various services is maximized (if that's what your goal is).

    Running a local "daemon-monitoring daemon" is one option--monit does a
    good job. Checking services over the network, as nagios does well, is
    another solution.



    Jonathan Gardner wrote:
    > On Mar 13, 11:32 pm, Gilles Ganault <> wrote:
    >
    >> I'd like to monitor connections to a remote SSH and web server. Does
    >> someone have some code handy that would try to connect every 5mn, and
    >> print an error if the script can't connect?
    >>

    >
    > from time import sleep
    > while True:
    > # Try to connect. May want to spawn a subprocess running a simple
    > shell script
    > # Handle success / failure appropriately
    > sleep 5*60 # Sleep for 5 minutes
    >
    > What you monitor is up to you. At a basic level, you can see if the
    > server is accepting connections. At a higher level, see if you can get
    > a page or see if you can login as a specific person. At a higher
    > level, you may want to check what is on the page or what happens when
    > you log in. It's all up to you.
    >
    >
    >



    --
    Shane Geiger
    IT Director
    National Council on Economic Education
    | 402-438-8958 | http://www.ncee.net

    Leading the Campaign for Economic and Financial Literacy
    Shane Geiger, Mar 14, 2008
    #3
  4. Gilles Ganault

    Pacman Guest

    Gilles Ganault <> wrote:
    >I'd like to monitor connections to a remote SSH and web server. Does
    >someone have some code handy that would try to connect every 5mn, and
    >print an error if the script can't connect?


    This script has been pretty reliable for us for the past few years,
    much more reliable than the expect script it replaced.

    #!/usr/bin/python
    import sys
    import pexpect
    quiet = open("/dev/null", "rw")
    sys.stdin = quiet
    sys.stdout = quiet
    sys.stderr = quiet
    smtp = pexpect.spawn("telnet " + sys.argv[1] + " 25")
    smtp.expect('220', timeout=120)
    smtp.sendline("quit\n^]q")

    Pacman
    Pacman, Mar 14, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joe Reazor

    Viewstate and Mulitple Web Servers

    Joe Reazor, Aug 28, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    336
    Chris Jackson
    Aug 28, 2003
  2. gemel
    Replies:
    1
    Views:
    300
    John Oakes
    Jun 10, 2004
  3. Sandeep
    Replies:
    2
    Views:
    442
  4. Replies:
    1
    Views:
    356
    bruno modulix
    May 10, 2005
  5. News123

    sshd in python for windows 7

    News123, Feb 7, 2010, in forum: Python
    Replies:
    4
    Views:
    1,025
    News123
    Feb 7, 2010
Loading...

Share This Page