Saltstack custom returner using Fluent+mysql for results collection

Source: Internet
Author: User
Tags saltstack

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>. *) \&quot, \" (<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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.