syslog.syslog

Here are the examples of the python api syslog.syslog taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

106 Examples 7

Example 101

Project: hubblemon
Source File: mysql_query.py
View license
def query(param, ip):
	print(param)

	if 'server' not in param:
		return 'select server'	

	server = param['server']

	id = ''
	pw = ''
	query = ''
	dbname = ''

	if 'id' in param:
		if isinstance(param['id'], list):
			id = param['id'][0]
		else:
			id = param['id']

	if 'pw' in param:
		if isinstance(param['pw'], list):
			pw = param['pw'][0]
		else:
			pw = param['pw']

	if 'query' in param:
		query = param['query']

	if 'db' in param:
		dbname = param['db']

	if param['query_type'] == 'query':
		conn = pymysql.connect(host=server, user=id, passwd=pw, db=dbname)
		cursor = conn.cursor()

		syslog('[hubblemon-mysql-query:%s-%s-%s(%s)] %s' % (server, dbname, id, ip, query))
		ret = cursor.execute(query)
		#print(ret)

		return common.core.return_as_table(cursor)

	
	else: # exec
		conn = pymysql.connect(host=server, user=id, passwd=pw, db=dbname)
		cursor = conn.cursor()

		p = {'conn':conn, 'cursor':cursor, 'result':'None' }

		syslog('[hubblemon-mysql-eval:%s-%s-%s(%s)] %s' % (server, dbname, id, ip, query))
		exec(query)

		return p['result']

Example 102

Project: hubblemon
Source File: redis_query.py
View license
def query(param, ip):
	print(param)

	if 'server' not in param:
		return 'select server'	


	server = param['server']
	instance = param['instance']
	dummy, port_suffix = instance.split('_')
	port, suffix = port_suffix.split('.')

	id = ''
	pw = ''
	query = ''

	if 'id' in param:
		if isinstance(param['id'], list):
			id = param['id'][0]
		else:
			id = param['id']

	if 'pw' in param:
		if isinstance(param['pw'], list):
			pw = param['pw'][0]
		else:
			pw = param['pw']

	if 'query' in param:
		query = param['query']


	if param['query_type'] == 'query':
		syslog('[hubblemon-redis-query:%s-%s(%s)] %s' % (server, id, ip, query))
		result_str = ''

		result_str += '[%s-%s]<br>%s<br>' % (server, port, common.core.return_as_string(do_redis_command(server, port, query)))
				
		return result_str

	else: # exec
		conn = redis.StrictRedis(server, port)
		
		p = {'conn':conn, 'result':'None' }

		syslog('[hubblemon-redis-eval:%s-%s(%s)] %s' % (server, id, ip, query))
		exec(query)

		return p['result']

Example 103

Project: networking-bigswitch
Source File: rhlib.py
View license
def get_uplinks_and_chassisid():
    """Get uplinks and chassis_id in RHOSP environment.
    :returns: a list of uplinks names and one chassis_id
        which is the first active nic's mac address.
    """
    intf_indexes = []
    while True:
        if not os.path.isfile(NET_CONF_PATH):
            time.sleep(1)
            continue
        try:
            json_data = open(NET_CONF_PATH).read()
            data = jsonutils.loads(json_data)
        except ValueError:
            time.sleep(1)
            continue
        network_config = data.get('network_config')
        for config in network_config:
            if config.get('type') != 'ovs_bridge':
                continue
            if config.get('name') != 'br-ex':
                continue
            members = config.get('members')
            for member in members:
                if member.get('type') not in SUPPORTED_BOND:
                    continue
                nics = member.get('members')
                for nic in nics:
                    if nic.get('type') != 'interface':
                        continue
                    nic_name = nic.get('name')
                    indexes = map(int, re.findall(r'\d+', nic_name))
                    if len(indexes) == 1 and nic_name.startswith("nic"):
                        intf_indexes.append(str(indexes[0] - 1))
                    else:
                        intf_indexes.append(str(nic_name))
                break
            break
        break

    intfs = []
    chassis_id = "00:00:00:00:00:00"
    while True:
        active_intfs = utils.ordered_active_nics()
        intf_len = len(active_intfs)
        if len(active_intfs) != 0:
            chassis_id = get_mac_str(active_intfs[0])
        intfs = []
        all_nics_are_ready = True
        for index in intf_indexes:
            try:
                idx = int(index)
                if idx >= intf_len:
                    all_nics_are_ready = False
                    break
                intfs.append(active_intfs[idx])
            except ValueError:
                intfs.append(index)
        if all_nics_are_ready:
            break
        LOG.syslog("LLDP gets partial active uplinks %s" % intfs)
        time.sleep(1)
    return intfs, chassis_id

Example 104

Project: networking-bigswitch
Source File: send_lldp.py
View license
def send_lldp():
    args = parse_args()
    if args.daemonize:
        daemonize()

    def _generate_senders_frames(intfs, chassisid, args):
        senders = []
        frames = []
        systemname = socket.gethostname()
        if args.system_name:
            systemname = args.system_name
        LOG.syslog("LLDP system-name is %s" % systemname)
        systemdesc = SYSTEM_DESC
        if args.system_desc:
            systemdesc = args.system_desc
        LOG.syslog("LLDP system-desc is %s" % systemdesc)
        for intf in intfs:
            interface = intf.strip()
            frame = lldp_frame_of(chassis_id=chassisid,
                                  network_interface=interface,
                                  ttl=TTL,
                                  system_name=systemname,
                                  system_desc=systemdesc)
            frames.append(frame)
            s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW)
            s.bind((interface, 0))
            senders.append(s)
        return senders, frames

    intfs = []
    platform_os = platform.linux_distribution()[0]
    chassisid = "00:00:00:00:00:00"
    if args.network_interface:
        intfs = args.network_interface.split(',')
    elif "red hat" in platform_os.strip().lower():
        try:
            intfs, chassisid = get_uplinks_and_chassisid()
        except Exception:
            intfs = []
    LOG.syslog("LLDP interfaces are %s" % ','.join(intfs))
    LOG.syslog("LLDP chassisid is %s" % chassisid)

    senders, frames = _generate_senders_frames(intfs, chassisid, args)
    interval = INTERVAL
    if args.interval:
        interval = args.interval
    LOG.syslog("LLDP interval is %d" % interval)
    while True:
        for idx, s in enumerate(senders):
            try:
                s.send(frames[idx])
            except Exception:
                continue
        time.sleep(interval)

Example 105

Project: temper-python
Source File: snmp.py
View license
    def write_log(self, message, prio=syslog.LOG_INFO):
        syslog.syslog(prio, message)

Example 106

Project: nyx
Source File: qradar.py
View license
def add(indicator,settings, reference_sets):
    """ places the indicator in a reference set"""
    reference_set_map=settings[reference_sets]
    if 'type' in indicator.keys() and indicator['type']=='Address - ipv4-addr':
        # adding an ip
        add_to_reference_set(reference_set_map[indicator['type']], indicator['ip'], get_sources(indicator), settings)
        return True
    elif 'type' in indicator.keys() and indicator['type']=='A':
        # adding the domain
        add_to_reference_set(reference_set_map[indicator['type']], indicator['domain'], get_sources(indicator), settings)
        return True
    elif 'md5' in indicator.keys():
        # adding the md5 hash
        if indicator['md5']:
            add_to_reference_set(reference_set_map['md5'], indicator['md5'], get_sources(indicator), settings)
        return True
    elif 'x_mailer' in indicator.keys():
        # adding the email address - for now, assuming spearphish, therefore focusing on the <<from>> field
        add_to_reference_set(reference_set_map['email'], indicator['from'], get_sources(indicator), settings)
        return True
    elif 'organization_id' in indicator.keys() and 'email_address' in indicator.keys():
        # adding a target email
        if indicator['email_address']:
            add_to_reference_set(reference_set_map['email'], indicator['email_address'], get_sources(indicator), settings)
        # adding the userid
        if indicator['organization_id']:
            add_to_reference_set(reference_set_map['userid'], indicator['organization_id'], get_sources(indicator), settings)
        return True
    else:
        syslog.syslog('nyx->QRadar: I do not know how to handle the following observable: %s' % str(indicator))
        return False