Ejemplo n.º 1
0
def is_not_syslog():
    '''
	Search if dont any match if string and hos i syslog
	'''
    sql = """
	SELECT DISTINCT a.hosts, m.FromHost, a.alert, m.Message FROM alert a 
		LEFT JOIN view_SystemEvents_compact m 
			ON 
			(m.Message LIKE CONCAT('%',a.alert,'%') 
				AND 
					a.hosts = m.FromHost 
						AND 
					m.DeviceReportedTime BETWEEN '{1}' AND '{0}')  
			WHERE m.Message IS NULL 
				AND a.status='OK'""".format(now.strftime("%Y-%m-%d %H:%M:%S"),
                                past.strftime("%Y-%m-%d %H:%M:%S"))
    fromdb = mysql_query(sql)
    rows = fromdb.fetchall()
    if not rows:
        print "OK"
    else:
        print "CRITICAL"
        for row in rows:
            print "NOT in Syslog Host " + str(row[0]) + " String: " + str(
                row[2])
def clean_mysql():
	'''
	Cleaning out mysql from delete strings inserted into logadmin site.
	Run every day to clean out from non intressted log enteris.
	'''

	#What date to use for deleteing
	sql="""
	DELETE 
		v 
	from 
		SystemEvents v 
			LEFT JOIN Exclude e ON (v.Message LIKE concat('%',e.exclude,'%')) 
		WHERE 
			e.exclude IS NOT NULL AND  
			v.DeviceReportedTime BETWEEN '{0} 00:00:00' AND '{0} 23:59:59' AND 
		e.status = 'DELETE'""".format(date.today())
	
	#Runningg sql
	mysql_query(sql)
	
	#Logging to syslog
	logthis ="logger -t syco-task -s 'Cleaning logserver mysql from excludes'"
	subprocess.Popen(logthis.split())
Ejemplo n.º 3
0
def clean_mysql():
    '''
	Cleaning out mysql from delete strings inserted into logadmin site.
	Run every day to clean out from non intressted log enteris.
	'''

    #What date to use for deleteing
    sql = """
	DELETE 
		v 
	from 
		SystemEvents v 
			LEFT JOIN Exclude e ON (v.Message LIKE concat('%',e.exclude,'%')) 
		WHERE 
			e.exclude IS NOT NULL AND  
			v.DeviceReportedTime BETWEEN '{0} 00:00:00' AND '{0} 23:59:59' AND 
		e.status = 'DELETE'""".format(date.today())

    #Runningg sql
    mysql_query(sql)

    #Logging to syslog
    logthis = "logger -t syco-task -s 'Cleaning logserver mysql from excludes'"
    subprocess.Popen(logthis.split())
Ejemplo n.º 4
0
def is_in_syslog_CRTICAL():
	'''
	Search if match is in database
	'''
	sql ="""
	select id,Message from view_SystemEvents_compact v 
		LEFT JOIN alert a ON (v.Message LIKE concat('%',a.alert,'%')) 
			WHERE a.alert IS NOT NULL AND   
				v.DeviceReportedTime BETWEEN '{1}' AND '{0}' AND a.status ='CRITICAL'""".format(now.strftime("%Y-%m-%d %H:%M:%S"),past.strftime("%Y-%m-%d %H:%M:%S"))
	fromdb = mysql_query(sql)
	rows = fromdb.fetchall()
	if not rows:
		print "OK"
	else:
		for row in rows:
			print "Match Found "+row[1]
Ejemplo n.º 5
0
def is_in_syslog_CRTICAL():
    '''
	Search if match is in database
	'''
    sql = """
	select id,Message from view_SystemEvents_compact v 
		LEFT JOIN alert a ON (v.Message LIKE concat('%',a.alert,'%')) 
			WHERE a.alert IS NOT NULL AND   
				v.DeviceReportedTime BETWEEN '{1}' AND '{0}' AND a.status ='CRITICAL'""".format(
        now.strftime("%Y-%m-%d %H:%M:%S"), past.strftime("%Y-%m-%d %H:%M:%S"))
    fromdb = mysql_query(sql)
    rows = fromdb.fetchall()
    if not rows:
        print "OK"
    else:
        for row in rows:
            print "Match Found " + row[1]
Ejemplo n.º 6
0
def is_not_syslog():
	'''
	Search if dont any match if string and hos i syslog
	'''
	sql ="""
	SELECT DISTINCT a.hosts, m.FromHost, a.alert, m.Message FROM alert a 
		LEFT JOIN view_SystemEvents_compact m 
			ON 
			(m.Message LIKE CONCAT('%',a.alert,'%') 
				AND 
					a.hosts = m.FromHost 
						AND 
					m.DeviceReportedTime BETWEEN '{1}' AND '{0}')  
			WHERE m.Message IS NULL 
				AND a.status='OK'""".format(now.strftime("%Y-%m-%d %H:%M:%S"),past.strftime("%Y-%m-%d %H:%M:%S"))
	fromdb = mysql_query(sql)
	rows = fromdb.fetchall()
	if not rows:
		print "OK"
	else:
		print "CRITICAL"
		for row in rows:
			print "NOT in Syslog Host "+str(row[0])+" String: "+str(row[2])