#bin/bash
##crontab -e
#0 0 * * * /bin/bash /root/zabbix_xput.sh
IP=xxxxxxxxxxxxx
PASSWPRD=xxxxxxxxxxxxxxx
zabbix_xput () {
date=`date -d "0 days ago" +%Y-%m-%d`
curl -H "Content-Type:application/json" -u $PASSWPRD -XPUT http://$IP/uint_$date -d '{"settings":{"number_of_replicas":1,"number_of_shards":5},"mappings":{"properties":{"itemid":{"type":"long"},"clock":{"format":"epoch_second","type":"date"},"value":{"type":"long"}}}}'
curl -H "Content-Type:application/json" -u $PASSWPRD -XPUT http://$IP/dbl_$date -d '{"settings":{"number_of_replicas":1,"number_of_shards":5},"mappings":{"properties":{"itemid":{"type":"long"},"clock":{"format":"epoch_second","type":"date"},"value":{"type":"double"}}}}'
curl -H "Content-Type:application/json" -u $PASSWPRD -XPUT http://$IP/log_$date -d '{"settings":{"number_of_replicas":1,"number_of_shards":5},"mappings":{"properties":{"itemid":{"type":"long"},"clock":{"format":"epoch_second","type":"date"},"value":{"fields":{"analyzed":{"index":true,"type":"text","analyzer":"standard"}},"index":false,"type":"text"}}}}'
curl -H "Content-Type:application/json" -u $PASSWPRD -XPUT http://$IP/text_$date -d '{"settings":{"number_of_replicas":1,"number_of_shards":5},"mappings":{"properties":{"itemid":{"type":"long"},"clock":{"format":"epoch_second","type":"date"},"value":{"fields":{"analyzed":{"index":true,"type":"text","analyzer":"standard"}},"index":false,"type":"text"}}}}'
curl -H "Content-Type:application/json" -u $PASSWPRD -XPUT http://$IP/str_$date -d '{"settings":{"number_of_replicas":1,"number_of_shards":5},"mappings":{"properties":{"itemid":{"type":"long"},"clock":{"format":"epoch_second","type":"date"},"value":{"fields":{"analyzed":{"index":true,"type":"text","analyzer":"standard"}},"index":false,"type":"text"}}}}'
}
zabbix_xput
以上是创建的脚本! 发现的两点原因如下:
1是因为zabbix-server配置文件导致的:
HistoryStorageDateIndex=1 没有开启!。
2、是因为zabbix索引没有初始化索引导致:
curl -H "Content-Type:application/json" -XPUT http://IP/_template/uint_template -d '{"template":"uint*","index_patterns":["uint*"],"settings":{"number_of_replicas":1,"number_of_shards":5},"mappings":{"properties":{"itemid":{"type":"long"},"clock":{"format":"epoch_second","type":"date"},"value":{"type":"long"}}}}'
curl -H "Content-Type:application/json" -XPUT http://IP/_template/dbl_template -d '{"template":"dbl*","index_patterns":["dbl*"],"settings":{"number_of_replicas":1,"number_of_shards":5},"mappings":{"properties":{"itemid":{"type":"long"},"clock":{"format":"epoch_second","type":"date"},"value":{"type":"double"}}}}'
curl -H "Content-Type:application/json" -XPUT http://IP/_template/log_template -d '{"template":"log*","index_patterns":["log*"],"settings":{"number_of_replicas":1,"number_of_shards":5},"mappings":{"properties":{"itemid":{"type":"long"},"clock":{"format":"epoch_second","type":"date"},"value":{"fields":{"analyzed":{"index":true,"type":"text","analyzer":"standard"}},"index":false,"type":"text"}}}}'
curl -H "Content-Type:application/json" -XPUT http://IP/_template/text_template -d '{"template":"text*","index_patterns":["text*"],"settings":{"number_of_replicas":1,"number_of_shards":5},"mappings":{"properties":{"itemid":{"type":"long"},"clock":{"format":"epoch_second","type":"date"},"value":{"fields":{"analyzed":{"index":true,"type":"text","analyzer":"standard"}},"index":false,"type":"text"}}}}'
curl -H "Content-Type:application/json" -XPUT http://IP/_template/str_template -d '{"template":"str*","index_patterns":["str*"],"settings":{"number_of_replicas":1,"number_of_shards":5},"mappings":{"properties":{"itemid":{"type":"long"},"clock":{"format":"epoch_second","type":"date"},"value":{"fields":{"analyzed":{"index":true,"type":"text","analyzer":"standard"}},"index":false,"type":"text"}}}}'
curl -H "Content-Type:application/json" -XPUT http://IP/_ingest/pipeline/uint-pipeline -d '{"description":"daily uint index naming","processors":[{"date_index_name":{"field":"clock","date_formats":["UNIX"],"index_name_prefix":"uint_","date_rounding":"d"}}]}'
curl -H "Content-Type:application/json" -XPUT http://IP/_ingest/pipeline/dbl-pipeline -d '{"description":"daily dbl index naming","processors":[{"date_index_name":{"field":"clock","date_formats":["UNIX"],"index_name_prefix":"dbl_","date_rounding":"d"}}]}'
curl -H "Content-Type:application/json" -XPUT http://IP/_ingest/pipeline/log-pipeline -d '{"description":"daily log index naming","processors":[{"date_index_name":{"field":"clock","date_formats":["UNIX"],"index_name_prefix":"log_","date_rounding":"d"}}]}'
curl -H "Content-Type:application/json" -XPUT http://IP/_ingest/pipeline/text-pipeline -d '{"description":"daily text index naming","processors":[{"date_index_name":{"field":"clock","date_formats":["UNIX"],"index_name_prefix":"text_","date_rounding":"d"}}]}'
curl -H "Content-Type:application/json" -XPUT http://IP/_ingest/pipeline/str-pipeline -d '{"description":"daily str index naming","processors":[{"date_index_name":{"field":"clock","date_formats":["UNIX"],"index_name_prefix":"str_","date_rounding":"d"}}]}'