Logstash-plugins
Logstash-プラグイン
Logstashは、パイプラインの3つのステージすべて(入力、フィルター、出力)にさまざまなプラグインを提供します。 これらのプラグインは、ユーザーがWebサーバー、データベース、ネットワークプロトコルなどのさまざまなソースからログをキャプチャするのに役立ちます。
キャプチャ後、Logstashはデータを解析し、ユーザーの必要に応じて意味のある情報に変換できます。 最後に、Logstashはその意味のある情報をElasticsearch、AWS Cloudwatchなどのさまざまな宛先ソースに送信または保存できます。
入力プラグイン
Logstashの入力プラグインは、ユーザーがさまざまなソースからログを抽出および受信するのに役立ちます。 入力プラグインを使用するための構文は次のとおりです-
Input {
Plugin name {
Setting 1……
Setting 2……..
}
}
次のコマンドを使用して、入力プラグインをダウンロードできます-
>Logstash-plugin install Logstash-input-<plugin name>
Logstashプラグインユーティリティは、Logstashインストールディレクトリの* binフォルダー*にあります。 次の表に、Logstashが提供する入力プラグインのリストを示します。
Sr.No. | Plugin name & Description |
---|---|
1 |
beats エラスティックビートフレームワークからログデータまたはイベントを取得します。 |
2 |
cloudwatch Amazon Web Servicesが提供するAPIであるCloudWatchからイベントを抽出します。 |
3 |
couchdb_changes このプラグインを使用して出荷されたcouchdbの_chages URIからのイベント。 |
4 |
drupal_dblog DBLogを有効にしてdrupalのウォッチドッグロギングデータを抽出します。 |
5 |
Elasticsearch Elasticsearchクラスターで実行されたクエリの結果を取得します。 |
6 |
eventlog Windowsイベントログからイベントを取得します。 |
7 |
exec Logstashの入力としてシェルコマンド出力を取得します。 |
8 |
file 入力ファイルからイベントを取得します。 これは、Logstashが入力ソースとともにローカルにインストールされ、入力ソースログにアクセスできる場合に役立ちます。 |
9 |
generator ランダムイベントを作成するテスト目的で使用されます。 |
10 |
github GitHub webhookからイベントをキャプチャします。 |
11 |
graphite グラファイトモニタリングツールからメトリックデータを取得します。 |
12 |
heartbeat テストにも使用され、イベントのようなハートビートを生成します |
13 |
http 2つのネットワークプロトコルを介してログイベントを収集するには、これらはhttpとhttpsです。 |
14 |
http_poller イベントへのHTTP API出力をデコードするために使用されます。 |
15 |
jdbc JDBCトランザクションをLogstashのイベントに変換します。 |
16 |
jmx JMXを使用してリモートJavaアプリケーションからメトリックを抽出します。 |
17 |
log4j TCPソケットを介してLog4jのsocketAppenderオブジェクトからイベントをキャプチャします。 |
18 |
rss Logstashの入力イベントとしてのコマンドラインツールの出力。 |
19 |
tcp TCPソケットを介してイベントをキャプチャします。 |
20 |
twitterストリーミングAPIからイベントを収集します。 |
21 |
unix UNIXソケット経由でイベントを収集します。 |
22 |
websocket Websocketプロトコルでイベントをキャプチャします。 |
23 |
xmpp Jabber/xmppプロトコルを介してイベントを読み取ります。 |
プラグイン設定
すべてのプラグインには固有の設定があり、プラグインでポート、パスなどの重要なフィールドを指定するのに役立ちます。 入力プラグインの設定について説明します。
File
この入力プラグインは、入力ソースに存在するログまたはテキストファイルからイベントを直接抽出するために使用されます。 UNIXのtailコマンドと同様に機能し、最後の読み取りカーソルを保存し、入力ファイルから新しい追加データのみを読み取りますが、star_position設定を使用して変更できます。 この入力プラグインの設定は次のとおりです。
Setting Name | Default Value | Description |
---|---|---|
add_field | \{} | Append a new field to the input event. |
close_older | 3600 | The files having last read time (in seconds) more than the specified in this plugin is closed. |
codec | “plain” | It is used to decode the data before entering into the Logstash pipeline. |
delimiter | “\n” | It is used to specify a new line delimiter. |
discover_interval | 15 | It is the time interval (in seconds) between discovering new files in the specified path. |
enable_metric | true | It is used to enable or disable the reporting and collection of metric for the specified plugin. |
exclude | It is used to specify the filename or patterns, which should be excluded from input plugin. | |
Id | To specify a unique identity for that plugin instance. | |
max_open_files | It specifies the maximum number of input files by Logstash at any time. | |
path | Specify the path of the files and it can contain the patterns for filename. | |
start_position | “end” | You can change to “beginning”, if you want that; initially Logstash should start reading the files from the starting and not only the new log event. |
start_interval | 1 | It specifies the time interval in seconds, after which Logstash checks for the modified files. |
tags | To add any additional information, like Logstash, it adds "_grokparsefailure" in tags, when any log event failed to comply with the specified grok filter. | |
type | This is a special field, which you can add to an input event and it is useful in filters and kibana. |
エラスティックサーチ
この特定のプラグインは、Elasticsearchクラスターで検索クエリの結果を読み取るために使用されます。 以下は、このプラグインで使用される設定を持っています-
Setting Name | Default Value | Description |
---|---|---|
add_field | \{} | Same as in file plugin, it is used to append a field in input event. |
ca_file | It is used to specify the path of SSL certificate Authority file. | |
codec | “plain” | It is used to decode the input events from Elasticsearch before entering in the Logstash pipeline. |
docinfo | “false” | You can change it to true, if you want to extract the additional information like index, type and id from Elasticsearch engine. |
docinfo_fields | ["_index", "_type", "_id"] | You can eliminate any field, which you do not want in your Logstash input. |
enable_metric | true | It is used to enable or disable the reporting and collection of metric for that plugin instance. |
hosts | It is used to specify the addresses of all elasticsearch engines, which will be the input source of that Logstash instance. The syntax is host:port or IP:port. | |
Id | It is used to give a unique identity number to that specific input plugin instance. | |
index | "logstash-*" | It is used to specify the index name or a pattern, which Logstash will monitor by Logstash for input. |
password | For authentication purposes. | |
query | "\{ \"sort\": [ \"_doc\" ] }" | Query for the execution. |
ssl | false | Enable or disable secure socket layer. |
tags | To add any additional information in input events. | |
type | It is used to classify the input forms so that it will be easy to search all the input events at later stages. | |
user | For authentic purposes. |
イベントログ
この入力プラグインは、Windowsサーバーのwin32 APIからデータを読み取ります。 以下は、このプラグインの設定です-
Setting Name | Default Value | Description |
---|---|---|
add_field | \{} | Same as in file plugin, it is used to append a field in input event |
codec | “plain” | It is used to decode the input events from windows; before entering in the Logstash pipeline |
logfile | ["Application", "Security", "System"] | Events required in the input log file |
interval | 1000 | It is in milliseconds and defines the interval between two consecutive checks of new event logs |
tags | To add any additional information in input events | |
type | It is used to classify the input form a specific plugins to given type, so that it will be easy to search all the input events in later stages |
この入力プラグインは、ストリーミングAPIからtwitterのフィードを収集するために使用されます。 次の表は、このプラグインの設定について説明しています。
Setting Name | Default Value | Description |
---|---|---|
add_field | \{} | Same as in file plugin, it is used to append a field in input event |
codec | “plain” | It is used to decode the input events from windows; before entering in the Logstash pipeline |
consumer_key | It contains the twitter app’s consumer key. For more info, visit https://dev.twitter.com/apps/new | |
consumer_secret | It contains the twitter app’s consumer secret key. For more info, visit https://dev.twitter.com/apps/new | |
enable_metric | true | It is used to enable or disable the reporting and collection of metric for that plugin instance |
follows |
It specifies the user ids separated by commas and LogStash checks these users’ status in Twitter. 詳細については、をご覧ください | |
full_tweet | false | You can change it to true, if you want Logstash to read the full object return from twitter API |
id | It is used to give a unique identity number to that specific input plugin instance | |
ignore_retweets | False | You can change set it true to ignore the retweets in the input twitter feed |
keywords | It’s an array of keywords, which need to be tracked in the twitters input feed | |
language | It defines the language of the tweets needed by LogStash from input twitter feed. This is an array of identifier, which defines a specific language in twitter | |
locations | To filter out the tweets from input feed according to the location specified. This is an array, which contains longitude and latitude of the location | |
oauth_token | It is a required filed, which contains user oauth token. For more information please visit the following link https://dev.twitter.com/apps | |
oauth_token_secret | It is a required filed, which contains user oauth secret token. For more information please visit the following link https://dev.twitter.com/apps | |
tags | To add any additional information in input events | |
type | It is used to classify the input form a specific plugins to given type, so that it will be easy to search all the input events in later stages |
TCP
TCPは、TCPソケットを介してイベントを取得するために使用されます。モード設定で指定されているユーザー接続またはサーバーから読み取ることができます。 次の表は、このプラグインの設定について説明しています-
Setting Name | Default Value | Description |
---|---|---|
add_field | \{} | Same as in file plugin, it is used to append a field in input event |
codec | “plain” | It is used to decode the input events from windows; before entering in the Logstash pipeline |
enable_metric | true | It is used to enable or disable the reporting and collection of metric for that plugin instance |
host | “0.0.0.0” | The address of the server OS the client depends upon |
id | It contains the twitter app’s consumer key | |
mode | “server” | It is used to specify the input source is server or client. |
port | It defines the port number | |
ssl_cert | It is used to specify the path of SSL certificate | |
ssl_enable | false | Enable or disable SSL |
ssl_key | To specify the path of SSL key file | |
tags | To add any additional information in input events | |
type | It is used to classify the input form a specific plugins to given type, so that it will be easy to search all the input events in later stages |
Logstash –出力プラグイン
Logstashはさまざまな出力ソースをサポートし、データベース、ファイル、電子メール、標準出力などのさまざまなテクノロジーでサポートします。
出力プラグインを使用するための構文は次のとおりです-
output {
Plugin name {
Setting 1……
Setting 2……..
}
}
次のコマンドを使用して、出力プラグインをダウンロードできます-
>logstash-plugin install logstash-output-<plugin name>
- Logstash-pluginユーティリティ*は、Logstashインストールディレクトリのbinフォルダーにあります。 次の表に、Logstashが提供する出力プラグインを示します。
Sr.No. | Plugin Name & Description |
---|---|
1 |
CloudWatch このプラグインは、集約されたメトリックデータをAmazon WebサービスのCloudWatchに送信するために使用されます。 |
2 |
csv 出力イベントをコンマ区切りで書き込むために使用されます。 |
3 |
Elasticsearch Elasticsearchインデックスに出力ログを保存するために使用されます。 |
4 |
出力が生成されるときに、通知メールを送信するために使用されます。 ユーザーは、出力に関する情報を電子メールで追加できます。 |
5 |
exec 出力イベントに一致するコマンドの実行に使用されます。 |
6 |
ganglia それは、ガンジラのモンドへのメトリックを苦しめます。 |
7 |
gelf GELF形式でGraylog2の出力を生成するために使用されます。 |
8 |
google_bigquery イベントをGoogle BigQueryに出力します。 |
9 |
google_cloud_storage 出力イベントをGoogle Cloud Storageに保存します。 |
10 |
graphite Graphiteに出力イベントを保存するために使用されます。 |
11 |
graphtastic Windowsで出力メトリックを書き込むために使用されます。 |
12 |
hipchat 出力ログイベントをHipChatに保存するために使用されます。 |
13 |
http 出力ログイベントをhttpまたはhttpsエンドポイントに送信するために使用されます。 |
14 |
influxdb InfluxDBに出力イベントを保存するために使用されます。 |
15 |
irc 出力イベントをircに書き込むために使用されます。 |
16 |
mongodb 出力データをMongoDBに保存します。 |
17 |
nagios パッシブチェックの結果をNagiosに通知するために使用されます。 |
18 |
nagios_nsca NSCAプロトコルを介したパッシブチェックの結果をNagiosに通知するために使用されます。 |
19 |
opentsdb Logstash出力イベントをOpenTSDBに保存します。 |
20 |
pipe 出力イベントを別のプログラムの標準入力にストリーミングします。 |
21 |
rackspace 出力ログイベントをRackspace Cloudのキューサービスに送信するために使用されます。 |
22 |
redis rpushコマンドを使用して、出力ログデータをRedisキューに送信します。 |
23 |
riak 出力イベントをRiak分散キー/値ペアに保存するために使用されます。 |
24 |
s3 出力ログデータをAmazon Simple Storage Serviceに保存します。 |
25 |
sns 出力イベントをAmazonのSimple Notification Serviceに送信するために使用されます。 |
26 |
solr_http Solrの出力ログデータにインデックスを付けて保存します。 |
27 |
sps AWSのSimple Queue Serviceにイベントを出荷するために使用されます。 |
28 |
statsd 統計データをstatsdネットワークデーモンに送信するために使用されます。 |
29 |
stdout コマンドプロンプトのようなCLIの標準出力に出力イベントを表示するために使用されます。 |
30 |
syslog 出力イベントをsyslogサーバーに出荷するために使用されます。 |
31 |
tcp 出力イベントをTCPソケットに送信するために使用されます。 |
32 |
udp UDPを介して出力イベントをプッシュするために使用されます。 |
33 |
websocket WebSocketプロトコルを介して出力イベントをプッシュするために使用されます。 |
34 |
xmpp XMPPプロトコルを介して出力イベントをプッシュするために使用されます。 |
すべてのプラグインには固有の設定があり、プラグインでポート、パスなどの重要なフィールドを指定するのに役立ちます。 出力プラグインの設定について説明します。
エラスティックサーチ
Elasticsearch出力プラグインにより、Logstashは出力をElasticsearchエンジンの特定のクラスターに保存できます。 ELK Stackのパッケージに含まれているため、これはDevopsのエンドツーエンドソリューションを提供するため、これはユーザーの有名な選択肢の1つです。 次の表は、この出力プラグインの設定について説明しています。
Setting Name | Default Value | Description |
---|---|---|
action | index | It is used to define the action performed in Elasticsearch engine. Other values for this settings are delete, create, update, etc. |
cacert | It contains the path of file with .cer or .pem for server’s certificate validation. | |
codec | “plain” | It is used to encode the output logging data before sending it to the destination source. |
doc_as_upset | false | This setting is used in case of update action. It creates a document in Elasticsearch engine, if the document id is not specified in output plugin. |
document_type | It is used to store the same type of events in the same document type. If it is not specified, then the event type is used for the same. | |
flush_size | 500 | This is used for improving the performance of bulk upload in Elasticsearch |
hosts | [“127.0.0.1”] | It is an array of destination addresses for output logging data |
idle_flush_time | 1 | It defines the time limit (second) between the two flushes, Logstash forces flush after the specified time limit in this setting |
index | "logstash-%\{+YYYY.MM.dd}" | It is used to specify the index of Elasticsearch engine |
manage_temlpate | true | It is used to apply the default template in Elasticsearch |
parent | nil | It is used to specify the id of parent document in Elasticsearch |
password | It is used to authenticate the request to a secure cluster in Elasticsearch | |
path | It is used to specify the HTTP path of Elasticsearch. | |
pipeline | nil | It is used to set the ingest pipeline, user wish to execute for an event |
proxy | It is used to specify HTTP proxy | |
retry_initial_interval | 2 | It is used to set the initial time interval (seconds) between bulk retries. It get double after each retry until it reach to retry_max_interval |
retry_max_interval | 64 | It is used to set the maximum time interval for retry_initial_interval |
retry_on_conflict | 1 | It is the number of retries by Elasticsearch to update a document |
ssl | To enable or disable SSL/TLS secured to Elasticsearch | |
template | It contains the path of the customized template in Elasticsearch | |
template_name | "logstash" | This is used to name the template in Elasticsearch |
timeout | 60 | It is the timeout for network requests to Elasticsearch |
upsert | “” | It update the document or if the document_id does not exist, it creates a new document in Elasticsearch |
user | It contains the user to authenticate the Logstash request in secure Elasticsearch cluster |
Eメール
Logstashが出力を生成するときに、電子メール出力プラグインを使用してユーザーに通知します。 次の表は、このプラグインの設定について説明しています。
Setting Name | Default Value | Description |
---|---|---|
address | “localhost” | It is the address of mail server |
attachments | [] | It contains the names and locations of the attached files |
body | “” | It contains the body of email and should be plain text |
cc | It contains the email addresses in comma separated manner for the cc of email | |
codec | “plain” | It is used to encode the output logging data before sending it to the destination source. |
contenttype | "text/html; charset = UTF-8" | It is used to content-type of the email |
debug | false | It is used to execute the mail relay in debug mode |
domain | "localhost" | It is used to set the domain to send the email messages |
from | "[email protected]" | It is used to specify the email address of the sender |
htmlbody | “” | It is used to specify the body of email in html format |
password | It is used to authenticate with the mail server | |
port | 25 | It is used to define the port to communicate with the mail server |
replyto | It is used to specify the email id for reply-to field of email | |
subject | “” | It contains the subject line of the email |
use_tls | false | Enable or disable TSL for the communication with the mail server |
username | Is contains the username for the authentication with the server | |
via | “smtp” | It defines the methods of sending email by Logstash |
Http
この設定は、出力イベントをhttp経由で宛先に送信するために使用されます。 このプラグインには次の設定があります-
Setting Name | Default Value | Description |
---|---|---|
automatic_retries | 1 | It is used to set the number of http request retries by logstash |
cacert | It contains the path of file for server’s certificate validation | |
codec | “plain” | It is used to encode the output logging data before sending it to the destination source. |
content_type | I specifies the content type of http request to the destination server | |
cookies | true | It is used to enable or disable cookies |
format | "json" | It is used to set the format of http request body |
headers | It contains the information of http header | |
http_method | “” | It is used to specify the http method used in the request by logstash and the values can be "put", "post", "patch", "delete", "get", "head" |
request_timeout | 60 | It is used to authenticate with the mail server |
url | It is a required setting for this plugin to specify the http or https endpoint |
標準
stdout出力プラグインは、コマンドラインインターフェイスの標準出力に出力イベントを書き込むために使用されます。 これは、WindowsのコマンドプロンプトとUNIXのターミナルです。 このプラグインには次の設定があります-
Setting Name | Default Value | Description |
---|---|---|
codec | “plain” | It is used to encode the output logging data before sending it to the destination source. |
workers | 1 | It is used to specify number of workers for the output |
statsd
これは、UDPを介して宛先バックエンドサービスにマトリックスデータを送信するために使用されるネットワークデーモンです。 これは、WindowsのコマンドプロンプトとUNIXのターミナルです。 このプラグインには次の設定があります-
Setting Name | Default Value | Description |
---|---|---|
codec | “plain” | It is used to encode the output logging data before sending it to the destination source. |
count | \{} | It is used to define the count to be used in metrics |
decrement | [] | It is used to specify the decrement metric names |
host | “localhost” | It contains the address of statsd server |
increment | [] | It is used to specify the increment metric names |
port | 8125 | It contains the port of statsd server |
sample_rate | 1 | It is used specify the sample rate of metric |
sender | “%{host}” | It specifies the name of the sender |
set | \{} | It is used to specify a set metric |
timing | \{} | It is used to specify a timing metric |
workers | 1 | It is used to specify number of workers for the output |
フィルタープラグイン
Logstashは、入力ログを解析し、より構造化されたクエリしやすい形式に変換するためのさまざまなフィルタープラグインをサポートしています。
フィルタプラグインを使用するための構文は次のとおりです-
filter {
Plugin name {
Setting 1……
Setting 2……..
}
}
次のコマンドを使用して、フィルタプラグインをダウンロードできます-
>logstash-plugin install logstash-filter-<plugin name>
Logstashプラグインユーティリティは、Logstashインストールディレクトリのbinフォルダーにあります。 次の表に、Logstashが提供する出力プラグインを示します。
Sr.No. | Plugin Name & Description |
---|---|
1 |
aggregate このプラグインは、同じタイプのさまざまなイベントからデータを収集または集約し、最終イベントで処理します |
2 |
alter ユーザーがログイベントのフィールドを変更できるようにします。 |
3 |
anonymize フィールドの値を一貫したハッシュに置き換えるために使用されます |
4 |
cipher 出力イベントを宛先ソースに保存する前に暗号化するために使用されます |
5 |
clone Logstashで出力イベントの複製を作成するために使用されます |
6 |
collate 異なるログのイベントを時間またはカウントでマージします |
7 |
csv このプラグインは、セパレータに従って入力ログからデータを解析します |
8 |
date イベントのフィールドから日付を解析し、イベントのタイムスタンプとして設定します |
9 |
dissect このプラグインは、ユーザーが非構造化データからフィールドを抽出するのに役立ち、grokフィルターがそれらを簡単に正しく解析できるようにします |
10 |
drop これは、同じタイプまたは他の類似のすべてのイベントをドロップするために使用されます |
11 |
elapsed 開始イベントと終了イベントの間の時間を計算するために使用されます |
12 |
Elasticsearch Elasticsearchに存在する以前のログイベントのフィールドをLogstashの現在のフィールドにコピーするために使用されます |
13 |
extractnumbers ログイベントの文字列から数値を抽出するために使用されます |
14 |
geoip ログイベントに存在するIPの場所の緯度と経度を含むフィールドをイベントに追加します |
15 |
grok イベントを解析してフィールドを取得するために一般的に使用されるフィルタープラグインです |
16 |
i18n ログイベントのフィールドから特殊文字を削除します |
17 |
json イベントまたはイベントの特定のフィールドで構造化されたJsonオブジェクトを作成するために使用されます |
18 |
kv このプラグインは、ロギングデータのキーと値のペアをペアリングするのに役立ちます |
19 |
metrics 各イベントの継続時間のカウントなどのメトリックを集約するために使用されます |
20 |
multiline また、一般的に使用されるフィルタープラグインの1つであり、複数行のログデータを単一のイベントに変換する場合に役立ちます。 |
21 |
mutate このプラグインは、イベントのフィールドの名前変更、削除、置換、変更に使用されます |
22 |
range これは、イベント内のフィールドの数値を、予想される範囲および範囲内の文字列の長さと照合するために使用されていました。 |
23 |
ruby 任意のRubyコードを実行するために使用されます |
24 |
sleep これにより、Logstashは指定された時間だけスリープします |
25 |
split イベントのフィールドを分割し、そのイベントのクローンにすべての分割値を配置するために使用されます |
26 |
xml ログに存在するXMLデータを解析してイベントを作成するために使用されます |
コーデックプラグイン
コーデックプラグインは、入力または出力プラグインの一部にすることができます。 これらのプラグインは、ロギングデータの表示を変更またはフォーマットするために使用されます。 Logstashは複数のコーデックプラグインを提供し、それらは次のとおりです-
Sr.No. | Plugin Name & Description |
---|---|
1 |
avro このプラグインは、Logstashイベントをシリアル化してavroデータにエンコードするか、またはavroレコードをLogstashイベントにデコードします |
2 |
cloudfront このプラグインは、AWSクラウドフロントからエンコードされたデータを読み取ります |
3 |
cloudtrail このプラグインは、AWS cloudtrailからデータを読み取るために使用されます |
4 |
collectd これは、UDP経由で収集と呼ばれるバイナリプロトコルからデータを読み取ります |
5 |
compress_spooler Logstashのログイベントをスプールバッチに圧縮するために使用されます |
6 |
dots これは、すべてのイベントにドットを標準出力に設定することにより、パフォーマンスの追跡に使用されます |
7 |
es_bulk これは、ElasticsearchからのバルクデータをElasticsearchメタデータを含むLogstashイベントに変換するために使用されます |
8 |
graphite このコーデックは、データをグラファイトからイベントに読み取り、イベントをグラファイト形式のレコードに変更します |
9 |
gzip_lines このプラグインは、gzipでエンコードされたデータを処理するために使用されます |
10 |
json これは、Json配列の単一の要素を単一のLogstashイベントに変換するために使用されます |
11 |
json_lines 改行区切り文字を使用してJSONデータを処理するために使用されます |
12 |
line プラグインは、単一のライブでイベントを読み書きします。つまり、改行区切り文字の後に新しいイベントがあります。 |
13 |
multiline 複数行のロギングデータを単一のイベントに変換するために使用されます |
14 |
netflow このプラグインは、nertflow v5/v9データをlogstashイベントに変換するために使用されます |
15 |
nmap nmapの結果データをXML形式に解析します |
16 |
plain これは、区切り文字なしでテキストを読み取ります |
17 |
rubydebug このプラグインは、Rubyの素晴らしい印刷ライブラリを使用して出力Logstashイベントを書き込みます |
独自のプラグインを構築する
Logstashで独自のプラグインを作成することもできます。これは要件に合っています。 Logstash-pluginユーティリティは、カスタムプラグインを作成するために使用されます。 ここでは、イベントにカスタムメッセージを追加するフィルタープラグインを作成します。
基本構造を生成する
ユーザーは、logstash-pluginユーティリティーの生成オプションを使用して必要なファイルを生成できます。または、GitHubでも使用できます。
>logstash-plugin generate --type filter --name myfilter --path c:/tpwork/logstash/lib
ここでは、 type オプションを使用して、プラグインが入力、出力、またはフィルターのいずれかであることを指定します。 この例では、 myfilter という名前のフィルタープラグインを作成しています。 pathオプションは、プラグインディレクトリを作成するパスを指定するために使用されます。 上記のコマンドを実行すると、ディレクトリ構造が作成されていることがわかります。
プラグインを開発する
プラグインのコードファイルは、プラグインディレクトリの \ lib \ logstash \ filters フォルダーにあります。 ファイル拡張子は .rb になります。
私たちの場合、コードファイルは次のパス内にありました-
C:\tpwork\logstash\lib\logstash-filter-myfilter\lib\logstash\filters\myfilter.rb
メッセージを-デフォルト⇒「こんにちは、finddevguides.comで学習しています」に変更して、ファイルを保存します。
プラグインをインストールする
このプラグインをインストールするには、LogstashのGemfileを変更する必要があります。 このファイルはLogstashのインストールディレクトリにあります。 この例では、 C:\ tpwork \ logstash にあります。 任意のテキストエディターを使用してこのファイルを編集し、次のテキストを追加します。
gem "logstash-filter-myfilter",:path => "C:/tpwork/logstash/lib/logstash-filter-myfilter"
上記のコマンドでは、プラグインの名前とインストール用のプラグインの場所を指定します。 次に、Logstash-pluginユーティリティーを実行して、このプラグインをインストールします。
>logstash-plugin install --no-verify
テスト
ここでは、前の例の1つに myfilter を追加しています-
*logstash.conf*
このLogstash構成ファイルには、grokフィルタープラグインの後のフィルターセクションにmyfilterが含まれています。
input {
file {
path => "C:/tpwork/logstash/bin/log/input1.log"
}
}
filter {
grok {
match => [
"message", "%{LOGLEVEL:loglevel} - %{NOTSPACE:taskid} -
%{NOTSPACE:logger} - %{WORD:label}( - %{INT:duration:int})?" ]
}
myfilter{}
}
output {
file {
path => "C:/tpwork/logstash/bin/log/output1.log"
codec => rubydebug
}
}
- logstashを実行*
次のコマンドを使用してLogstashを実行できます。
>logstash –f logsatsh.conf
*input.log*
次のコードブロックは、入力ログデータを示しています。
INFO - 48566 - TRANSACTION_START - start
*output.log*
次のコードブロックは、出力ログデータを示しています。
{
"path" => "C:/tpwork/logstash/bin/log/input.log",
"@timestamp" => 2017-01-07T06:25:25.484Z,
"loglevel" => "INFO",
"logger" => "TRANSACTION_END",
"@version" => "1",
"host" => "Dell-PC",
"label" => "end",
"message" => "Hi, You are learning this on finddevguides.com",
"taskid" => "48566",
"tags" => []
}
Logstashで公開する
開発者は、githubにアップロードし、Elasticsearch Companyによって定義された標準化された手順に従ってカスタムプラグインをLogstashに公開することもできます。
公開の詳細については、次のURLを参照してください-
https://www.elastic.co/guide/en/logstash/current/contributing-to-logstashl