Created
June 9, 2011 19:16
-
-
Save marvin/1017480 to your computer and use it in GitHub Desktop.
syslog calculate facility and severity from PRI(priority)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Or perhaps use masking and bitshifting? C psuedo-code follows:
severity = priority & 0x07;
facility = priority >> 3;
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
syslog matrix http://chris-mccafferty.blogspot.com/2010/12/syslog-priority-matrix.html