Skip to content

Instantly share code, notes, and snippets.

@marvin
Created June 9, 2011 19:16
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save marvin/1017480 to your computer and use it in GitHub Desktop.
Save marvin/1017480 to your computer and use it in GitHub Desktop.
syslog calculate facility and severity from PRI(priority)
example:
PRI = 191
To get the Facility
Divide the PRI number by 8.
191/8 = 23.875
The whole number part is the facility.
To get the Severity
Take the whole number part 23 and multiply by 8 and the product subtract from 191:
191 - (23 * 8 )= 7
PRI = Facility 23 and Priority (7)
Work backword to check our work:
23*8 = 184 + 7 = 191
@marvin
Copy link
Author

marvin commented Jun 9, 2011

@andrewr123
Copy link

Or perhaps use masking and bitshifting? C psuedo-code follows:

severity = priority & 0x07;
facility = priority >> 3;

@quantenschaum
Copy link

or modulo and floor division
python example

p=191
s=p%8
f=p//8
print(s,f)
# yields 7 23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment