Splunk Search

sourceをいくつか設定していると最初のsourceの情報しかとってこない

appleman
Contributor

以下のqueryを実行すると、取ってきてほしい情報(UIDとwifi)がかけてしまいます。
原因はおそらくですが、sourceをいくつかORで繋いで指定しており、その中の一つのsource(source=device)からしか情報をとってきてないように見受けられます。
このsource=deviceは日次でデータを取得しており、その他は週次で取得しているためでしょうか。
かけている情報をだすだしかたを教えて下さい。

index=* sourcetype=d_log (source=*i_device OR source=*device OR source=*i_device_n OR source=*i_device_r)
| rex field=id "(?\d+)@"

| stats latest(c_id) AS CID latest(id) as ID latest(serial) AS Serial latest(type) AS Type latest(model) AS Model latest(version) AS Version latest(Carrier) AS Carrier latest(pp) AS PP latest(u_id) AS UID latest(wifi) AS wifi latest(enrolled_date) AS enrolled_date latest(lastmodified) as lastmodified by number

| eval Enrolled=strftime(enrolled_date,"%Y/%m/%d %H:%M")
| eval Lastupdated=strftime(lastmodified,"%Y/%m/%d %H:%M") | rename phone AS MSN
| table CID ID MSN Serial Type Model Version Carrier PP UID wifi Enrolled Lastupdated | transpose

0 Karma
1 Solution

Suda
Communicator

検索文について、「|」で分解し、どの部分に問題があるか、切り分けをされてはいかがでしょうか?

1) データの選択範囲が正しいか?

 sourcetype=d_log (source=i_device OR source=device OR source=i_device_n OR source=*i_device_r) 
| stats count by source

対象にしているsourceがカウントされているか、確認します。ここで対象から漏れている場合、inputs.confの設定を見直し、sourceとsourcetypeが期待通りに設定されるか、ご確認ください。

2) transpose

transposeでは引数を指定しないと、デフォルトは5となっています。transpose 10のように大きい数字を指定することで変化は見られませんか?

3) すべてのsourceにて、フィールド情報が含まれているでしょうか?fillnullの有無で件数に変化がないかを確認。

index= sourcetype=d_log (source=i_device OR source=device OR source=i_device_n OR source=*i_device_r) | rex field=id "(?<id>d+)@" | fillnull value="NULL" id c_id id serial type model version Carrier pp u_id wifi enrolled_date lastmodified number phone | stats latest(c_id) AS CID latest(id) as ID latest(serial) AS Serial latest(type) AS Type latest(model) AS Model latest(version) AS Version latest(Carrier) AS Carrier  latest(pp) AS PP latest(u_id) AS UID latest(wifi) AS wifi latest(enrolled_date) AS enrolled_date latest(lastmodified) as lastmodified by number | eval Enrolled=strftime(enrolled_date,"%Y/%m/%d %H:%M") | eval Lastupdated=strftime(lastmodified,"%Y/%m/%d %H:%M") | rename phone AS MSN | table CID ID MSN Serial Type Model Version Carrier PP UID wifi Enrolled Lastupdated | transpose

fillnullコマンドを追加する事で、期待結果が得られるなら、フィールドの値が正しく抽出できていないのかもしれません。

フィールド抽出設定をご確認ください。

フィールドが抽出できないケースが想定される場合には、fillnullコマンドによる対応が必要なのかもしれません。

参考にしていただければ幸いです。

View solution in original post

Suda
Communicator

検索文について、「|」で分解し、どの部分に問題があるか、切り分けをされてはいかがでしょうか?

1) データの選択範囲が正しいか?

 sourcetype=d_log (source=i_device OR source=device OR source=i_device_n OR source=*i_device_r) 
| stats count by source

対象にしているsourceがカウントされているか、確認します。ここで対象から漏れている場合、inputs.confの設定を見直し、sourceとsourcetypeが期待通りに設定されるか、ご確認ください。

2) transpose

transposeでは引数を指定しないと、デフォルトは5となっています。transpose 10のように大きい数字を指定することで変化は見られませんか?

3) すべてのsourceにて、フィールド情報が含まれているでしょうか?fillnullの有無で件数に変化がないかを確認。

index= sourcetype=d_log (source=i_device OR source=device OR source=i_device_n OR source=*i_device_r) | rex field=id "(?<id>d+)@" | fillnull value="NULL" id c_id id serial type model version Carrier pp u_id wifi enrolled_date lastmodified number phone | stats latest(c_id) AS CID latest(id) as ID latest(serial) AS Serial latest(type) AS Type latest(model) AS Model latest(version) AS Version latest(Carrier) AS Carrier  latest(pp) AS PP latest(u_id) AS UID latest(wifi) AS wifi latest(enrolled_date) AS enrolled_date latest(lastmodified) as lastmodified by number | eval Enrolled=strftime(enrolled_date,"%Y/%m/%d %H:%M") | eval Lastupdated=strftime(lastmodified,"%Y/%m/%d %H:%M") | rename phone AS MSN | table CID ID MSN Serial Type Model Version Carrier PP UID wifi Enrolled Lastupdated | transpose

fillnullコマンドを追加する事で、期待結果が得られるなら、フィールドの値が正しく抽出できていないのかもしれません。

フィールド抽出設定をご確認ください。

フィールドが抽出できないケースが想定される場合には、fillnullコマンドによる対応が必要なのかもしれません。

参考にしていただければ幸いです。

Splunk_Shinobi
Splunk Employee
Splunk Employee

おそらく各sourceにはnumberフィールドがあって、numberをキーとして複数のデータを連結するようなサーチだとおもいます。
statsの中のlatest()をvalues()に変更してみてはどうでしょうか。

0 Karma

appleman
Contributor

valuesでもいいのですが、最新の情報という意味でlatestを使用していました。でないと、結果が1つに特定できずに複数表示されてしまう可能性があるためです。

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...