Exemple #1
0
 def __get_graylog_handler(self, config):
     handler = None
     host = config["host"]
     port = config["port"]
     if config["type"].lower() == "udp":
         from pygelf import GelfUdpHandler
         handler = GelfUdpHandler(host=host,
                                  port=port,
                                  include_extra_fields=True)
     elif config["type"].lower() == "tcp":
         from pygelf import GelfTcpHandler
         handler = GelfTcpHandler(host=host,
                                  port=port,
                                  include_extra_fields=True)
     elif config["type"].lower() == "http":
         from pygelf import GelfHttpHandler
         handler = GelfHttpHandler(host=host,
                                   port=port,
                                   include_extra_fields=True)
     return handler
Exemple #2
0
import socket
import pytest
import mock
from pygelf import GelfTcpHandler, GelfUdpHandler, GelfHttpHandler, GelfTlsHandler
from tests.helper import logger, get_unique_message, log_warning, log_exception

SYSLOG_LEVEL_ERROR = 3
SYSLOG_LEVEL_WARNING = 4


@pytest.fixture(params=[
    GelfTcpHandler(host='127.0.0.1', port=12201),
    GelfUdpHandler(host='127.0.0.1', port=12202),
    GelfUdpHandler(host='127.0.0.1', port=12202, compress=False),
    GelfHttpHandler(host='127.0.0.1', port=12203),
    GelfHttpHandler(host='127.0.0.1', port=12203, compress=False),
    GelfTlsHandler(host='127.0.0.1', port=12204),
    # GelfTlsHandler(host='127.0.0.1', port=12204, validate=True, ca_certs='tests/config/cert.pem'),
])
def handler(request):
    return request.param


def test_simple_message(logger):
    message = get_unique_message()
    graylog_response = log_warning(logger, message)
    assert graylog_response['message'] == message
    assert graylog_response['level'] == SYSLOG_LEVEL_WARNING
    assert 'full_message' not in graylog_response
    assert 'file' not in graylog_response
    assert 'module' not in graylog_response
Exemple #3
0
import pytest
from pygelf import GelfTcpHandler, GelfUdpHandler, GelfHttpHandler, GelfTlsHandler
from tests.helper import logger, get_unique_message, log_warning


@pytest.fixture(params=[
    GelfTcpHandler(host='127.0.0.1', port=12201, debug=True),
    GelfUdpHandler(host='127.0.0.1', port=12202, debug=True),
    GelfUdpHandler(host='127.0.0.1', port=12202, compress=False, debug=True),
    GelfHttpHandler(host='127.0.0.1', port=12203, debug=True),
    GelfHttpHandler(host='127.0.0.1', port=12203, compress=False, debug=True),
    GelfTlsHandler(host='127.0.0.1', port=12204, debug=True),
    GelfTlsHandler(host='127.0.0.1',
                   port=12204,
                   debug=True,
                   validate=True,
                   ca_certs='tests/config/cert.pem'),
])
def handler(request):
    return request.param


def test_debug_mode(logger):
    message = get_unique_message()
    graylog_response = log_warning(logger, message)
    assert graylog_response['message'] == message
    assert graylog_response['file'] == 'helper.py'
    assert graylog_response['module'] == 'helper'
    assert graylog_response['func'] == 'log_warning'
    assert graylog_response['logger_name'] == 'test'
    assert 'line' in graylog_response
Exemple #4
0
from flask import Flask, render_template
from flask import jsonify
from flask import request
from flask_pymongo import PyMongo
from pygelf import GelfTcpHandler, GelfUdpHandler, GelfTlsHandler, GelfHttpHandler
import logging

app = Flask(__name__)

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger()
logger.addHandler(GelfTcpHandler(host='127.0.0.1', port=12201))
logger.addHandler(GelfUdpHandler(host='127.0.0.1', port=12201))
logger.addHandler(GelfTlsHandler(host='127.0.0.1', port=12201))
logger.addHandler(GelfHttpHandler(host='127.0.0.1', port=12201))

logger.info('hello gelf')

app.config['MONGO_DBNAME'] = 'db_teste_itau1'
app.config['MONGO_URI'] = 'mongodb://*****:*****@app.route('/tweets', methods=['GET'])
def get_all_tweets():
    teste4 = mongo.db.teste4
    output = []
    for s in teste4.find():
        output.append({'user': s['user'], 'date': s['date']})
Exemple #5
0
from pygelf import GelfTcpHandler, GelfUdpHandler, GelfHttpHandler, GelfTlsHandler
from tests.helper import logger, get_unique_message, log_warning


STATIC_FIELDS = {
    '_ozzy': 'diary of a madman',
    '_van_halen': 1984,
    '_id': 42
}


@pytest.fixture(params=[
    GelfTcpHandler(host='127.0.0.1', port=12201, **STATIC_FIELDS),
    GelfUdpHandler(host='127.0.0.1', port=12202, **STATIC_FIELDS),
    GelfUdpHandler(host='127.0.0.1', port=12202, compress=False, **STATIC_FIELDS),
    GelfHttpHandler(host='127.0.0.1', port=12203, **STATIC_FIELDS),
    GelfHttpHandler(host='127.0.0.1', port=12203, compress=False, **STATIC_FIELDS),
    GelfTlsHandler(host='127.0.0.1', port=12204, **STATIC_FIELDS),
    # GelfTlsHandler(host='127.0.0.1', port=12204, validate=True, ca_certs='tests/config/cert.pem', **STATIC_FIELDS),
    GelfTcpHandler(host='127.0.0.1', port=12201, static_fields=STATIC_FIELDS, _ozzy='billie jean'),
    GelfUdpHandler(host='127.0.0.1', port=12202, static_fields=STATIC_FIELDS, _ozzy='billie jean'),
    GelfUdpHandler(host='127.0.0.1', port=12202, compress=False, static_fields=STATIC_FIELDS, _ozzy='billie jean'),
    GelfHttpHandler(host='127.0.0.1', port=12203, static_fields=STATIC_FIELDS, _ozzy='billie jean'),
    GelfHttpHandler(host='127.0.0.1', port=12203, compress=False, static_fields=STATIC_FIELDS, _ozzy='billie jean'),
    GelfTlsHandler(host='127.0.0.1', port=12204, static_fields=STATIC_FIELDS),
    # GelfTlsHandler(host='127.0.0.1', port=12204, validate=True, ca_certs='tests/config/cert.pem', static_fields=STATIC_FIELDS, _ozzy='billie jean'),
])
def handler(request):
    return request.param

Exemple #6
0
# -*- coding: future_fstrings -*-
from pygelf import GelfHttpHandler
import logging


logging.basicConfig(level=logging.INFO)
logger = logging.getLogger()
logger.addHandler(GelfHttpHandler(host='127.0.0.1', port=5000, compress=False))

logger.info('hello gelf')
class DummyFilter(logging.Filter):
    def filter(self, record):
        record.ozzy = 'diary of a madman'
        record.van_halen = 1984
        record.id = 42
        return True


@pytest.fixture(params=[
    GelfTcpHandler(host='127.0.0.1', port=12201, include_extra_fields=True),
    GelfUdpHandler(host='127.0.0.1', port=12202, include_extra_fields=True),
    GelfUdpHandler(host='127.0.0.1',
                   port=12202,
                   compress=False,
                   include_extra_fields=True),
    GelfHttpHandler(host='127.0.0.1', port=12203, include_extra_fields=True),
    GelfHttpHandler(host='127.0.0.1',
                    port=12203,
                    compress=False,
                    include_extra_fields=True),
    GelfTlsHandler(host='127.0.0.1', port=12204, include_extra_fields=True),
    GelfTlsHandler(host='127.0.0.1',
                   port=12204,
                   validate=True,
                   ca_certs='tests/config/cert.pem',
                   include_extra_fields=True),
])
def handler(request):
    return request.param