FilesSection.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package info.fetter.logstashforwarder.config;
  2. /*
  3. * Copyright 2015 Didier Fetter
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. import java.util.List;
  19. import java.util.Map;
  20. import java.util.regex.Pattern;
  21. import org.apache.commons.lang.builder.ToStringBuilder;
  22. import com.fasterxml.jackson.annotation.JsonProperty;
  23. import info.fetter.logstashforwarder.Multiline;
  24. import java.io.UnsupportedEncodingException;
  25. public class FilesSection {
  26. private List<String> paths;
  27. private Map<String,String> fields;
  28. @JsonProperty("dead time")
  29. private String deadTime = "24h";
  30. private Multiline multiline;
  31. public List<String> getPaths() {
  32. return paths;
  33. }
  34. public void setPaths(List<String> paths) {
  35. this.paths = paths;
  36. }
  37. public Map<String, String> getFields() {
  38. return fields;
  39. }
  40. public void setFields(Map<String, String> fields) {
  41. this.fields = fields;
  42. }
  43. public String getDeadTime() {
  44. return deadTime;
  45. }
  46. public int getDeadTimeInSeconds() {
  47. int deadTimeInSeconds = 0;
  48. String remaining = deadTime;
  49. if(deadTime.contains("h")) {
  50. String[] splitByHour = deadTime.split("h",2);
  51. if(splitByHour.length > 1) {
  52. remaining = splitByHour[1];
  53. }
  54. deadTimeInSeconds += Integer.parseInt(splitByHour[0]) * 3600;
  55. }
  56. if(remaining.contains("m")) {
  57. String[] splitByMinute = remaining.split("m",2);
  58. if(splitByMinute.length > 1) {
  59. remaining = splitByMinute[1];
  60. }
  61. deadTimeInSeconds += Integer.parseInt(splitByMinute[0]) * 60;
  62. }
  63. if(remaining.contains("s")) {
  64. String[] splitBySecond = remaining.split("s",2);
  65. deadTimeInSeconds += Integer.parseInt(splitBySecond[0]);
  66. }
  67. return deadTimeInSeconds;
  68. }
  69. public void setDeadTime(String deadTime) {
  70. this.deadTime = deadTime;
  71. }
  72. public Multiline getMultiline() {
  73. return multiline;
  74. }
  75. public void setMultiline(Map<String, String> multilineMap) throws UnsupportedEncodingException {
  76. this.multiline = new Multiline(multilineMap);
  77. }
  78. @Override
  79. public String toString() {
  80. return new ToStringBuilder(this).
  81. append("paths", paths).
  82. append("fields", fields).
  83. append("dead time", deadTime).
  84. append("multiline", multiline).
  85. toString();
  86. }
  87. }