2019年12月25日水曜日

ダッシュボードのタイムレンジピッカーをさっぱりさせたい

ことの始まり

タイムレンジピッカーはとても便利なのですが、選択肢が多いためにダッシュボードの利用しかしない一般ユーザーにとってはとっつきにくいものと感じられる場合もあると思います。
そこでダッシュボードに表示させるタイムレンジピッカーの選択肢を減らすべく
https://answers.splunk.com/answers/222650/limit-choices-in-default-timepicker.html
をベースに非表示にさせるエレメントを探してみました。


やりかた

以下のXMLから表示させたいエレメントを削除してダッシュボードに埋め込めばよさそうです。途中に ^= で設定しているところがありますが(answersからコピペしているため)、これは前方一致なので、将来的に事故るかもしれません。あしからず。



  <row>
    <panel depends="$never$">
      <title>Hidden Embedded CSS</title>
      <html>
        <style>
           button[data-test^='Today'],
           button[data-test^='Yesterday'],
           button[data-test^='Business week to date'],
           button[data-test^='Week to date'],
           button[data-test^='Year to date'],
           button[data-test^='Month to date'],
           button[data-test^='Previous week'],
           button[data-test^='Previous business week'],
           button[data-test^='Previous month'],
           button[data-test^='Previous year'],
           button[data-test^='Last 15 minutes'],
           button[data-test^='Last 60 minutes'],
           button[data-test^='Last 4 hours'],
           button[data-test^='Last 24 hours'],
           button[data-test^='Last 7 days'],
           button[data-test^='Last 30 days'],
           div[data-test^='real-time-column'],
           div[data-test^='past'],
           div[data-test^='other-column'],
           div[data-test-panel-id^='presets'],
           div[data-test-panel-id^='advanced'],
           div[data-test-panel-id^='relative'],
           div[data-test-panel-id^='real'],
           div[data-test-panel-id='date']
           {
           display: none !important;
           }
        </style>
      </html>
    </panel>
  </row>

2019年11月22日金曜日

標準正規分布をSPLで


| makeresults count=801
| streamstats count
| eval x= (count - 401) /100
| eval y=1/(sqrt(2*pi())) * exp(-pow(x,2)/2)
| fields - _time count

参考
https://bellcurve.jp/statistics/blog/15344.html

2019年7月26日金曜日

SplunkとNetFlow その2

ことのはじまり

Splunk Add-on for NetFlowを使ってSplunkで直接NetFlowを取り込む方法を書きましたが、2019/03のSplunk社のBlogにてEnd of Supportが発表されていました。
https://www.splunk.com/blog/2019/03/18/end-of-availability-splunk-built-apps-and-add-ons.html

代替手段はStreamらしいので、今回はStreamを使って取り込んてみます。

設定

何も考えず(Docmentも読まずに)にStream をインストールして、Appを開くととりあえず怒られしまいます。環境はec2のAmazon Linuxで非rootユーザーでsplunkを動作させています。
shellを叩く必要があるとのことで、とりあえず叩きます。(Defaultでsplunkユーザーはsudoersに入ってないので事前に visudo で追加しておきます。)

shell実行後、Stream App上で「Redetect」をクリックすると正常であれば以下のような画面になります。

設定に移り、NetFlowを有効にします。



NetFlowコレクタとして動作させるための追加設定については如何に記載があります。
https://docs.splunk.com/Documentation/StreamApp/latest/DeployStreamApp/ConfigureFlowcollector

Documentに従って、/opt/splunk/etc/apps/Splunk_TA_stream/local/streamfwd.conf を以下のように設定して、splunkを再起動します。

[streamfwd]
netflowReceiver.0.ip = 172.31.27.223
netflowReceiver.0.port = 2055
netflowReceiver.0.decoder = netflow

Ciscoルーターの設定は前回と同じなので、port番号は2055を使ってます。

できあがり

途中、何度か再起動してたりするので何か気づいていないハマりどころがある気がしますが、StreamをFlowコレクタとして使うことで、NetFlowの可視化ができました。
フィールドもSplunk Add-on for NetFlowとくらべるとこちらの方がみやすい気がします。

2019年3月23日土曜日

sleep.py

Sleepするだけのカスタムコマンド作りたい


要KAIZEN


import splunk.Intersplunk
import time

if __name__ == '__main__':
    keywords,options = splunk.Intersplunk.getKeywordsAndOptions()
    sec = options.get('sec', '10')
    sec = int(sec)
    time.sleep(sec)
    results,dummyresults,settings = splunk.Intersplunk.getOrganizedResults()
    splunk.Intersplunk.outputResults(results)

サブサーチは何階層でもいけると思っていた

ことの始まり

どこかのお客さんに対して、
「サブサーチのネストは何階層でもいけますよ。メモリの許す限り」
的な発言をした記憶があったのだけど、limits.conf を眺めていたら Default で8階層だということをいま知った。

limits.conf.spec をみる

max_subsearch_depth = <int>* Maximum recursion depth for subsearches. Specifies the maximum levels for  subsearches.* It is considered a search exception if a subsearch does not stop after  this many levels.* Default: 8

一応、Default値があるというだけで制限値は書かれていないので、完全に間違った発言ではなかったと言い逃れしておきたい

制限超えるとどうなるか

単にエラーになるだけ。エラーメッセージが limits.conf をみるように促してくれるといいのに