"""
 Check how much HADSA data we have
"""
import os
import sys
import stat
import psycopg2
IEM = psycopg2.connect(database='iem', host='iemdb', user='nobody')
icursor = IEM.cursor()

def check():
    icursor.execute("""SELECT count(*) from current c JOIN stations s on
    (s.iemid = c.iemid)
    WHERE valid > now() - '75 minutes'::interval and network ~* 'ASOS'""")
    row = icursor.fetchone()

    return row[0]
    
if __name__ == '__main__':
    count = check()
    if count > 10000:
        print 'OK - %s count |count=%s;1000;5000;10000' % (count, count)
        sys.exit(0)
    elif count > 5000:
        print 'WARNING - %s count |count=%s;1000;5000;10000' % (count, count)
        sys.exit(1)
    else:
        print 'CRITICAL - %s count |count=%s;1000;5000;10000' % (count, count)
        sys.exit(2)
"""
 Check how much HADSA data we have
"""
import os
import sys
import stat
import psycopg2
IEM = psycopg2.connect(database='iem', host='iemdb', user='nobody')
icursor = IEM.cursor()

def check():
    icursor.execute("""SELECT count(*) from current c JOIN stations s on
    (s.iemid = c.iemid)
    WHERE valid > now() - '75 minutes'::interval and network ~* 'ASOS'""")
    row = icursor.fetchone()

    return row[0]
    
if __name__ == '__main__':
    count = check()
    if count > 3000:
        print 'OK - %s count |count=%s;1000;5000;10000' % (count, count)
        sys.exit(0)
    elif count > 2000:
        print 'WARNING - %s count |count=%s;1000;5000;10000' % (count, count)
        sys.exit(1)
    else:
        print 'CRITICAL - %s count |count=%s;1000;5000;10000' % (count, count)
        sys.exit(2)
adjust thresholds based on a night's worth of processing