Package org.graylog2.plugin
Class Tools
java.lang.Object
org.graylog2.plugin.Tools
Utility class for various tool/helper functions.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.joda.time.format.DateTimeFormatterstatic final org.joda.time.format.DateTimeFormatterstatic final org.joda.time.format.DateTimeFormatter -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Comparable<? super T>>
SortedSet<T>asSortedSet(Collection<T> c) static StringbuildElasticSearchTimeFormat(org.joda.time.DateTime timestamp) static StringbytesToHex(byte[] a) static org.joda.time.DateTimedateTimeFromDouble(double x) The double representation of a UNIX timestamp with milliseconds is a strange, human readable format.static org.joda.time.DateTimeParse the string representation of an ISO 8601 date/timestamp with milliseconds and timezone.static StringdecodeBase64(String what) static StringdecompressGzip(byte[] compressedData) Decompress GZIP (RFC 1952) compressed datastatic StringdecompressGzip(byte[] compressedData, long maxBytes) Decompress GZIP (RFC 1952) compressed datastatic StringdecompressZlib(byte[] compressedData) Decompress ZLIB (RFC 1950) compressed datastatic StringdecompressZlib(byte[] compressedData, long maxBytes) Decompress ZLIB (RFC 1950) compressed datastatic StringTry to parse a date in ES_DATE_FORMAT format considering it is in UTC and convert it to an ISO8601 date.static StringencodeBase64(String what) static Optional<AbsoluteRange>extractHistogramBoundaries(String query) static Stringstatic DoubleConvert something to a double in a fast way having a good guess that it is a double.static StringgetISO8601String(org.joda.time.DateTime time) static <T,E> T getKeyByValue(Map<T, E> map, E value) static Stringstatic Stringstatic Numberstatic StringgetPID()Get the own PID of this process.static StringGet a String containing version information of JRE, OS, ...static intgetTimestampDaysAgo(int ts, int days) static URIgetUriWithDefaultPath(URI uri, String path) static URIgetUriWithPort(URI uri, int port) static URIgetUriWithScheme(URI uri, String scheme) static intstatic doubleGet the current UNIX epoch with milliseconds of the systemstatic doublegetUTCTimestampWithMilliseconds(long timestamp) Get the UNIX epoch with milliseconds of the provided millisecond timestampstatic InetAddressguessPrimaryNetworkAddress(boolean preferIPv4) Try to get the primaryInetAddressof the primary network interface with fallback to the local loopback address (usually127.0.0.1or::1.static org.joda.time.DateTimeiso8601()Deprecated.static booleanisWildcardInetAddress(InetAddress inetAddress) static URInormalizeURI(URI uri, String scheme, int port, String path) static org.joda.time.DateTimenow(org.joda.time.DateTimeZone dateTimeZone) static org.joda.time.DateTimenowUTC()static StringrdnsLookup(InetAddress socketAddress) static StringsafeSubstring(String target, int start, int end) static voidThe default uncaught exception handler will print to STDERR, which we don't always want for threads.static StringsyslogFacilityToReadable(int facility) Converts integer syslog facility to human readable stringstatic StringsyslogLevelToReadable(int level) Converts integer syslog loglevel to human readable stringstatic org.joda.time.format.DateTimeFormatterAccepts our ElasticSearch time formats without milliseconds.static URIuriWithTrailingSlash(URI uri)
-
Field Details
-
ES_DATE_FORMAT_FORMATTER
public static final org.joda.time.format.DateTimeFormatter ES_DATE_FORMAT_FORMATTER -
ES_DATE_FORMAT_NO_MS_FORMATTER
public static final org.joda.time.format.DateTimeFormatter ES_DATE_FORMAT_NO_MS_FORMATTER -
ISO_DATE_FORMAT_FORMATTER
public static final org.joda.time.format.DateTimeFormatter ISO_DATE_FORMAT_FORMATTER
-
-
Method Details
-
getPID
Get the own PID of this process.- Returns:
- PID of the running process
-
syslogLevelToReadable
Converts integer syslog loglevel to human readable string- Parameters:
level- The level to convert- Returns:
- The human readable level
-
syslogFacilityToReadable
Converts integer syslog facility to human readable string- Parameters:
facility- The facility to convert- Returns:
- The human readable facility
-
getSystemInformation
Get a String containing version information of JRE, OS, ...- Returns:
- Descriptive string of JRE and OS
-
decompressZlib
Decompress ZLIB (RFC 1950) compressed data- Parameters:
compressedData- A byte array containing the ZLIB-compressed data.- Returns:
- A string containing the decompressed data
- Throws:
IOException
-
decompressZlib
Decompress ZLIB (RFC 1950) compressed data- Parameters:
compressedData- A byte array containing the ZLIB-compressed data.maxBytes- The maximum number of uncompressed bytes to read.- Returns:
- A string containing the decompressed data
- Throws:
IOException
-
decompressGzip
Decompress GZIP (RFC 1952) compressed data- Parameters:
compressedData- A byte array containing the GZIP-compressed data.- Returns:
- A string containing the decompressed data
- Throws:
IOException
-
decompressGzip
Decompress GZIP (RFC 1952) compressed data- Parameters:
compressedData- A byte array containing the GZIP-compressed data.maxBytes- The maximum number of uncompressed bytes to read.- Returns:
- A string containing the decompressed data
- Throws:
IOException
-
getUTCTimestamp
public static int getUTCTimestamp()- Returns:
- The current UTC UNIX timestamp.
-
getUTCTimestampWithMilliseconds
public static double getUTCTimestampWithMilliseconds()Get the current UNIX epoch with milliseconds of the system- Returns:
- The current UTC UNIX timestamp with milliseconds.
-
getUTCTimestampWithMilliseconds
public static double getUTCTimestampWithMilliseconds(long timestamp) Get the UNIX epoch with milliseconds of the provided millisecond timestamp- Parameters:
timestamp- a millisecond timestamp (milliseconds since UNIX epoch)- Returns:
- The current UTC UNIX timestamp with milliseconds.
-
getLocalHostname
-
getLocalCanonicalHostname
-
getTimestampDaysAgo
public static int getTimestampDaysAgo(int ts, int days) -
encodeBase64
-
decodeBase64
-
rdnsLookup
- Throws:
UnknownHostException
-
generateServerId
-
asSortedSet
-
buildElasticSearchTimeFormat
-
dateTimeFromDouble
public static org.joda.time.DateTime dateTimeFromDouble(double x) The double representation of a UNIX timestamp with milliseconds is a strange, human readable format. This sucks and no format should use the double representation. Change GELF to use long. (zomg) -
dateTimeFromString
Parse the string representation of an ISO 8601 date/timestamp with milliseconds and timezone. -
timeFormatterWithOptionalMilliseconds
public static org.joda.time.format.DateTimeFormatter timeFormatterWithOptionalMilliseconds()Accepts our ElasticSearch time formats without milliseconds.- Returns:
- A DateTimeFormatter suitable to parse an ES_DATE_FORMAT formatted string to a DateTime Object even if it contains no milliseconds.
-
nowUTC
public static org.joda.time.DateTime nowUTC() -
now
public static org.joda.time.DateTime now(org.joda.time.DateTimeZone dateTimeZone) -
iso8601
Deprecated.UsenowUTC()instead.- Returns:
- The current date with timezone UTC.
-
getISO8601String
-
elasticSearchTimeFormatToISO8601
Try to parse a date in ES_DATE_FORMAT format considering it is in UTC and convert it to an ISO8601 date. If an error is encountered in the process, it will return the original string. -
safeSubstring
- Parameters:
target- String to cut.start- Character position to start cutting at. Inclusive.end- Character position to stop cutting at. Exclusive!- Returns:
- Extracted/cut part of the string or null when invalid positions where provided.
-
getDouble
Convert something to a double in a fast way having a good guess that it is a double. This is perfect for MongoDB data that *should* have been stored as doubles already so there is a high probability of easy converting.- Parameters:
x- The object to convert to a double- Returns:
- Converted object, 0 if empty or something went wrong.
-
getNumber
-
guessPrimaryNetworkAddress
Try to get the primaryInetAddressof the primary network interface with fallback to the local loopback address (usually127.0.0.1or::1.- Returns:
- The primary
InetAddressof the primary network interface or the loopback address as fallback. - Throws:
SocketException- if the list of network interfaces couldn't be retrieved
-
isWildcardInetAddress
-
getUriWithPort
-
getUriWithScheme
-
getUriWithDefaultPath
-
uriWithTrailingSlash
-
normalizeURI
-
getKeyByValue
-
bytesToHex
-
silenceUncaughtExceptionsInThisThread
public static void silenceUncaughtExceptionsInThisThread()The default uncaught exception handler will print to STDERR, which we don't always want for threads. Using this utility method you can avoid writing to STDERR on a per-thread basis -
extractHistogramBoundaries
-
nowUTC()instead.