Connecting to Remote machines and getting the log files and rendering in front end

Question

Hi All,

       I'm new to Python and Django. How can I develop this using Python and Django.

I have 4 remote machines, I need to login to all machines and I need to get the logs from them. After getting the logs parse the logs and need to present that in front end. What are the modules I can use for connecting to remote machines.

Guest April 8, 2016, 6:27 a.m. 4 Answer

Answers ( 4 )

  1. April 10, 2016, 3:01 p.m.

    Hi,

    there are many python modules that will allow you to connect remotly .

    I prefer  http://www.pythonforbeginners.com/modules-in-python/python-secure-ftp-module

    pip install pysftp 

     

    something like

     

    import pysftp

    def getfiles(request):
        srv = pysftp.Connection(host="your_FTP_server", username="your_username",
        password="your_password")
        # Download the file from the remote server
        srv.get(/pathtofile/file1.log)
        srv.close()
        data = open("file1.log", "r")
        return render_to_response('index.html',
        {
        "data":data,

        }
        ,context_instance=RequestContext(request))

     

    if you need more help feel free to comment this answer ...  or  if you want I can do it for you.  You can hire me through oDesk.

  2. April 19, 2016, 12:07 p.m.

    Hi Thanks for the answer you posted. I'm able to connect to remote machine and able to get the file. But when send the data to render in HTML, I can see the content of the file, but the content displayed is in list and it has all new line charactes.

    This is what i have done. 

    # Open log file

    data = open("file1.log", "r")

    # read whole conetnt of the file

    data_lines=data.readlines()

    return render_to_response('index.html',
        {
        "data_lines":data_lines,

        }
        ,context_instance=RequestContext(request))

     

    # In index.html I'm using this {{ data_lines }} to dsiplay. This displays a list structure in HTML. How can I dsiplay the content properly.

    for ex: now I'm getting like this.

    ['hello world\n','django framework\n']

    I want to display in this manner:

    hello world

    django framework

    Please can you help you out here.

  3. April 20, 2016, 4:57 a.m.

    Hi 

    you can use django template tags to iterate through data_lines

    In index.html put this code 

    {% for d in data_lines%}

    {{d}}

    {%endfor%}

    you can find more about django  template language at 

    https://docs.djangoproject.com/en/1.9/ref/templates/builtins/

     

  4. April 20, 2016, 11:55 a.m.

    Hi Thanks for the answer you posted. I'm able to connect to remote machine and able to get the file. But when send the data to render in HTML, I can see the content of the file, but the content displayed is in list and it has all new line charactes.

    This is what i have done. 

    # Open log file

    data = open("file1.log", "r")

    # read whole conetnt of the file

    data_lines=data.readlines()

    return render_to_response('index.html',
        {
        "data_lines":data_lines,

        }
        ,context_instance=RequestContext(request))

     

    # In index.html I'm using this {{ data_lines }} to dsiplay. This displays a list structure in HTML. How can I dsiplay the content properly.

    for ex: now I'm getting like this.

    ['hello world\n','django framework\n']

    I want to display in this manner:

    hello world

    django framework

    Please can you help you out here.

Warning! You are not logged in.
Your answer will be published as Guest user.

Post your Answer

 Prev question