User Profile

Collapse

Profile Sidebar

Collapse
kaf3773
kaf3773
Last Activity: Mar 10 '16, 09:47 PM
Joined: Jan 4 '12
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • query for max date value for each item in a WHERE IN clause

    Hello,

    I am trying to query the data set below for the data_value for the data_id of the recent data_date.

    So for data_id 18554 the recent data_date will be 2/8/2016 18:40 and its data_value will be 29504.76

    And for data_id 18555 the recent data_date will be 2/8/2016 18:40 and its data_value will be -90909090909

    Code:
    data_id	data_name	data_date	data_value
    18554	traffic_in	2/8/2016
    ...
    See more | Go to post

  • python-rrdtool try except rrdtool.error module object has no attribute error

    I have this code that gives this error on Linux and will be grateful if you can help
    Code:
    import rrdtool
    
    try:      
          ret_asd = rrdtool.update(myfile.rrd,'N:%s:%s' %(metric1, metric2));    
    except rrdtool.error, e:
          print e
    When i run the above i get the below error

    Code:
    except rrdtool.error, e:
    AttributeError: 'module' object has no attribute 'error'
    ...
    See more | Go to post

  • kaf3773
    replied to fetching values from rrd file
    After a number of hours at this here is the code i came up with that works for me. improvements to this will be very much appreciated.
    Code:
    trmaxTuples = rrdtool.fetch("mutime.rrd", 'AVERAGE', '-s -2hr')
    n = trmaxTuples[2]
    p = 0
    for p in range(len(n)):
        s = n[p]
        print s
        first = s[0]
        print first
        second = s[1]
        print second
        third = s[2]
    ...
    See more | Go to post

    Leave a comment:


  • kaf3773
    replied to fetching values from rrd file
    I am trying to extend this code for an rrd file with multiple datasources.

    When i run this code
    Code:
    trmaxTuples = rrdtool.fetch("mutime.rrd", 'AVERAGE', '-s -2hr')
    for item in trmaxTuples:
            n = item[1]
            if n > 50:
                print n
            else:
                print "x"
    i get the results below
    Code:
    -bash-3.2$ /opt/csw/bin/python
    ...
    See more | Go to post

    Leave a comment:


  • Python regular expression to pick values in a string

    Hi
    I have the output below stored in a variable called outping. I am trying to pick the values in bold into two variables using python regular expressions. i will appreciate your help. Thanks

    Type escape sequence to abort.
    Sending 100, 100-byte ICMP Echos to 192.168.1.8, timeout is 2 seconds:
    !!!!!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!
    !!!!!!!!!!!!!!! !!!!!!!!!!!!!!!
    Success rate...
    See more | Go to post

  • kaf3773
    replied to fetching values from rrd file
    Smashing!! Thanks a lot bvdet this worked.
    See more | Go to post

    Leave a comment:


  • kaf3773
    started a topic fetching values from rrd file

    fetching values from rrd file

    Hi
    I am trying to cycle through values i fetch from an rrd file with a python script and this is the code i have
    Code:
    output = rrdtool.fetch("mutime.rrd", 'AVERAGE')
    trmaxTuples = output[2]
    n  = len(trmaxTuples)
    for n in trmaxTuples:
        if (trmaxTuples > 100):
            print n
        else:
            print "0"
    Here is the result i get...
    See more | Go to post

  • kaf3773
    replied to spawn snmptrap from python
    Hi,

    I got it to work and this is the code i used
    Code:
    import subprocess
    from subprocess import Popen, PIPE
    path = "-v 2c -c public 192.168.2.162 '' SNMPv2-SMI::enterprises.3.1.1"
    Popen(['/opt/csw/bin/snmptrap', '%s' % path], shell=True, stdout=PIPE, stderr=subprocess.STDOUT)
    If someone also has a better way to do it i will appreciate that as well.
    Thanks
    See more | Go to post

    Leave a comment:


  • kaf3773
    started a topic spawn snmptrap from python

    spawn snmptrap from python

    Hi
    I am trying to spawn an snmptrap from python but i keep getting the following error

    Invalid version specified after -v flag: 2c -c public 192.168.2.162 SNMPv2-SMI::enterprise s.3.1.1

    here is the python code i am using
    Code:
    from subprocess import Popen
    Popen(['snmptrap', '-v 2c -c public 192.168.2.162 SNMPv2-SMI::enterprises.3.1.1'])
    When i test the same command from the...
    See more | Go to post

  • kaf3773
    replied to python rrdtool try catch statement
    hi bvdet

    Thanks a lot for your answer it worked and this is my final code
    hope it helps others too
    Code:
    for i in range(numrowed):
                    row = curred.fetchone()
                    time_stamp = row[0]
                    rx_max = row[1]
                    try:
                        ret = rrdtool.update(ds_file.rrd,'%s:%s' %(time_stamp,rx_max));
                    except rrdtool.error, e:
    ...
    See more | Go to post

    Leave a comment:


  • kaf3773
    started a topic python rrdtool try catch statement

    python rrdtool try catch statement

    Hi

    I have a Python script that updates an rrd file with data it pulls from a database. Here is a snippet of the Python code
    Code:
    for i in range(numrowed):
                    row = curred.fetchone()
                    time_stamp = row[0]
                    rx_max = row[1]
                    
                    ret = rrdtool.update(ds_file.rrd,'%s:%s' %(time_stamp,rx_max));
    ...
    See more | Go to post

  • kaf3773
    started a topic pexpect telnet login from one device to another

    pexpect telnet login from one device to another

    I am trying to use pexpect to telnet to a device and then subsequently telnet from that device to another device and then output the result of a command on the second device but i am unable to. Here is the script i wrote and the error i am getting

    I will appreciate help very much. Thanks

    Code:
    import pexpect
    
    child = pexpect.spawn('telnet 192.168.2.45');
    
    child.expect('assword:');
    ...
    See more | Go to post

  • kaf3773
    replied to python regular expression screen scrub
    Thank you so much bvdet. All the above you suggested do exactly what i want. I really appreciate.

    Could you kindly explain it to me
    See more | Go to post

    Leave a comment:


  • kaf3773
    started a topic python regular expression screen scrub

    python regular expression screen scrub

    Hi

    I am trying to write a python script that executes a command to screen scrub results below
    I will appreciate it very much if you can help me with a python script that can
    pick the percentage USAGE in the second column based on the supplied queue number in the first column
    Thanks in advance.

    Code:
    import re
    content = """NUMBER of Queues = 5
    SYSTEM Treshold = 80%
    ...
    See more | Go to post

  • i finally figured it out by doing this


    cur.execute(""" select switch,percent_ occupied from Table_name where switch = '4DYHTE' and trunc(date_time ) = ('%s')""" % (prev_day))
    See more | Go to post

    Leave a comment:


  • Hello Glenton,

    Sorry about this but i made a mistake about the error i was getting.

    When i run it with or without the quotes this is the error message i get
    Traceback (most recent call last):
    File "spit.py", line 9, in <module>
    ('4DYHTE') and trunc(date_time ) = %s""",("prev_da y",))
    cx_Oracle.Datab aseError: ORA-01036: illegal variable name/number
    ...
    See more | Go to post

    Leave a comment:


  • Well i am trying to pass the data in the variable prev_day which is in this format dd-mon-yy to the SQL query.

    without the quotes i get an invalid variable error
    See more | Go to post

    Leave a comment:


  • Thanks for the pointer Glenton. I got it to work by doing this
    csv_writer = csv.writer(csv_ file, delimiter="\t")

    I am trying to use a date in an SQL where clause

    prevday = datetime.date.t oday()-datetime.timede lta(1)
    prev_day = prevday.strftim e("%d-%b-%y")

    and this is the SQL statement but it does not work

    cur.execute(""" select switch,percent_ occupied...
    See more | Go to post

    Leave a comment:


  • Change the comma delimiter in python output to csv

    I am trying to output a list to a csv file and the line below work fine.

    I need help with changing the delimiter from the default comma(,) to tab delimited.
    csv_file = open('output.cs v', 'w')
    csv_writer = csv.writer(csv_ file)

    Help very much appreciated

    Kaf
    See more | Go to post

  • kaf3773
    started a topic SQL IN statement on oracle via python

    SQL IN statement on oracle via python

    I need help trying to execute this SQL statement on an oracle database via python.

    select switch,switch|| '-'||tkg_name as tkg_name,(date_ time - to_date('01-JAN-1970','DD-MON-YYYY')) * (86400)as date_time,perce nt_occupied from Table_name where tkg_name in ('AB65UT','LIY8 70','IUY890') and
    trunc(date_time ) between '21-DEC-11' and '27-DEC-11';

    I also like to know how to escape the single quotes in the SQL statement....
    See more | Go to post
No activity results to display
Show More
Working...