MySQL table structure
Custom Returner
Fluent acquisition
Client Configuration
Server-side configuration
Background: Salt comes with a lot of optional returner, but all need to do configuration in Minion, I feel that this is pretty fucked, and just as we use fluent on the platform to do the acquisition, then customize a reutren, and then use the fluent acquisition, processing, storage
The following procedures are described:
MySQL table structure
CREATE TABLE ' fluent ';
CREATE TABLE ' Salt_returns ' (
' ID ' mediumint (9) Not NULL auto_increment,
' Jid ' char (DEFAULT NULL),
' host_id ' varchar DEFAULT NULL,
' Time ' timestamp not NULL DEFAULT Current_timestamp,
' Fun ' varchar (+) DEFAULT NULL,
' Return ' text,
' Success ' char (5) DEFAULT NULL,
PRIMARY KEY (' id '),
KEY ' idx_host_id ' (' host_id ')
Custom Returner
Create a directory of default custom return, although this directory is default, but default does not create
# mkdir/srv/salt/_returners
Custom Returner
The main thing is returner (ret), the definition of this function
/srv/salt/_returners/lcoal_return.py
#coding =utf8
Import JSON
Def __virtual__ ():
Return ' Local_return '
def returner (ret):
‘‘‘
Return data to the local file
‘‘‘
Result_file = '/var/local/salt/returner '
result = File (Result_file, ' A + ')
Result.write (str (Json.dumps (Ret.values ())) [1:-1]+ ' \ n ')
Result.close ()
Synchronize to all nodes:
Salt ' * ' saltutil.sync_returners
Execute command
Salt ' * ' cmd.run ' Ls/var '--return Local_return
View results:
# Cat/var/log/salt/returner
"Cmd.run", "20130524052158870765", "cache\ncvs\ndb\nempty\ngames\nlib\nlocal\nlock\nlog\nmail\nnis\nopt\ Npreserve\nrun\nspool\ntmp\nwww\nyp "," Minion1 ", True
Fluent acquisition
Client Configuration
<source>
Type tail
Path/var/log/salt/returner
Pos_file/tmp/return_pos.log
Tag Os.salt
Format/\" (? <fun>. *) \", \" (<jid>\d+) \", (? <return>. *), \" (? <id>. *) \", (? <success>. *)/
</source>
<match os.*>
Type forward
Flush_interval 1s
<server>
Host {{pillar[' host '}}
Port {{pillar[' port '}}
</server>
</match>
Server-side configuration
<source>
Type forward
Port 24224
Bind 0.0.0.0
</source>
<match host.os.salt>
Type MySQL
Host localhost
Database fluent
Username Fluent
Password fluent
Key_names jid,id,fun,return,success
SQL INSERT into Salt_returns (Jid,host_id,fun, ' return ', success) VALUES (?,?,?,?,?)
Flush_interval 5s
</match>
Result query:
SELECT * FROM Salt_returns where success are not NULL and fun= ' cmd.run ' limit 1;
+------+----------------------+-----------------------------------------+---------------------+---------+------ ---+---------+
| ID | Jid | host_id | Time | Fun | return | Success |
+------+----------------------+-----------------------------------------+---------------------+---------+------ ---+---------+
| 2571 | 20130531184127393793 | Test | 2013-05-31 10:38:29 | Cmd.run | "/root" | true |
+------+----------------------+-----------------------------------------+---------------------+---------+------ ---+---------+
This article from "Davideylee" blog, declined reprint!
Saltstack custom returner using Fluent+mysql for results collection