Giter Site home page Giter Site logo

syslog_protocol's Introduction

Syslog protocol

roughly conforms to the murky shade of grey known as http://www.faqs.org/rfcs/rfc3164.html

Examples

Manipulate packets manually

require 'syslog_protocol'

p = SyslogProtocol::Packet.new
p.hostname = "space_station"
p.facility = "kern"
p.severity = "warn"
p.tag = "test"
p.content = "flight control broken"
p.to_s
# => "<4>Aug  1 14:01:17 space_station flight control broken"
p.pri
# => 4
p.facility
# => 0
p.facility_name
# => "kern"
p.severity_name
# => "warn"
p.warn?
# => true
p.info?
# => false

Use a Logger to generate packets

require 'syslog_protocol'

logger = SyslogProtocol::Logger.new("space_station", "uucp")
logger.debug("looking for uucp on board the space station")
# => "<67>Aug  1 14:02:29 space_station looking for uucp on board the space station"
logger.emerg("omg we cant find uucp on the space station")
# => "<64>Aug  1 14:03:56 space_station omg we cant find uucp on the space station"

Parse packets

require 'syslog_protocol'

p = SyslogProtocol.parse("<34>Oct 11 22:14:15 space_station space is really getting to me")
p.facility
# => 4
p.severity_name
# => "crit"
p.time
# => Sun Oct 11 22:14:15 -0700 2009
p.content
# => "space is really getting to me"

It yells at you for trying to abuse the protocol

p = SyslogProtocol::Packet.new
p.facility = 34534534
# => ArgumentError: Facility must be within 0-23
p.hostname = "my host"
# => ArgumentError: Hostname may not contain spaces
p.hostname = "h\000stname"
# => ArgumentError: Hostname may only contain ASCII characters 33-126
# ...etc.
# It will also unintelligently truncate messages > 1024 bytes so beware.

Caveats

Syslog is a terrible and loosely defined protocol. Many devices and programs do not conform to it and so their packets may not be parsed correctly by this interpretation, nor may the packets generated by this necessarily be recognized by other devices or programs ;)

This is probably wrong and buggy, and i know the code is ugly, thanks.

Good luck.

TODO

  • Update to more closely map to the ruby syslog API where possible

syslog_protocol's People

Contributors

eric avatar jakedouglas avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.