Class: LogStash::Outputs::MicrosoftSentinelOutputInternal::LogAnalyticsClient
- Inherits:
-
Object
- Object
- LogStash::Outputs::MicrosoftSentinelOutputInternal::LogAnalyticsClient
- Defined in:
- lib/logstash/sentinel_la/logAnalyticsClient.rb
Class Method Summary collapse
-
.is_successfully_posted(response) ⇒ Object
Static function to return if the response is OK or else.
Instance Method Summary collapse
-
#initialize(logstashLoganalyticsConfiguration) ⇒ LogAnalyticsClient
constructor
A new instance of LogAnalyticsClient.
-
#post_data(body) ⇒ Object
Post the given json to Azure Loganalytics.
Constructor Details
#initialize(logstashLoganalyticsConfiguration) ⇒ LogAnalyticsClient
Returns a new instance of LogAnalyticsClient.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/logstash/sentinel_la/logAnalyticsClient.rb', line 17 def initialize(logstashLoganalyticsConfiguration) @logstashLoganalyticsConfiguration = logstashLoganalyticsConfiguration @logger = @logstashLoganalyticsConfiguration.logger la_api_version = "2023-01-01" @uri = sprintf("%s/dataCollectionRules/%s/streams/%s?api-version=%s",@logstashLoganalyticsConfiguration.data_collection_endpoint, @logstashLoganalyticsConfiguration.dcr_immutable_id, logstashLoganalyticsConfiguration.dcr_stream_name, la_api_version) @aadTokenProvider=LogAnalyticsAadTokenProvider::new(logstashLoganalyticsConfiguration) @userAgent = getUserAgent() # Auto close connection after 60 seconds of inactivity @connectionAutoClose = { :last_use => Time.now, :lock => Mutex.new, :max_idel_time => 60, :is_closed => true } @timer = Thread.new do loop do sleep @connectionAutoClose[:max_idel_time] / 2 if is_connection_stale? @connectionAutoClose[:lock].synchronize do if is_connection_stale? reset_connection end end end end end end |
Class Method Details
.is_successfully_posted(response) ⇒ Object
Static function to return if the response is OK or else
75 76 77 |
# File 'lib/logstash/sentinel_la/logAnalyticsClient.rb', line 75 def self.is_successfully_posted(response) return (response.status >= 200 && response.status < 300 ) ? true : false end |
Instance Method Details
#post_data(body) ⇒ Object
Post the given json to Azure Loganalytics
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/logstash/sentinel_la/logAnalyticsClient.rb', line 51 def post_data(body) raise ConfigError, 'no json_records' if body.empty? response = nil @connectionAutoClose[:lock].synchronize do #close connection if its stale if is_connection_stale? reset_connection end if @connectionAutoClose[:is_closed] open_connection end headers = get_header() # Post REST request response = @connection.request(method: :post, body: body, headers: headers) @connectionAutoClose[:is_closed] = false @connectionAutoClose[:last_use] = Time.now end return response end |