search
HomeDatabaseMysql Tutorialsalt+自定义returner+fluent+mysql进行结果采集

背景:salt自带的有很多可选的returner,但是都需要在minion做配置,我感觉这点挺操蛋,而且正好我们平台上在使用fluent做采集,于是就自定义一个reutren,然后用fluent采集,处理,入库 过程如下: 1:mysql表结构: CREATE TABLE `fluent`;CREATE TABLE `salt_returns

背景: salt自带的有很多可选的returner,但是都需要在minion做配置,我感觉这点挺操蛋, 而且正好我们平台上在使用fluent做采集,于是就自定义一个reutren,然后用fluent采集,处理,入库

过程如下:

1:mysql表结构:

CREATE TABLE `fluent`;
CREATE TABLE `salt_returns` (
  `id` mediumint(9) NOT NULL AUTO_INCREMENT,
  `jid` char(20) DEFAULT NULL,
  `host_id` varchar(48) DEFAULT NULL,
  `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `fun` varchar(30) DEFAULT NULL,
  `return` text,
  `success` char(5) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_host_id` (`host_id`)
)

2:自定义returners

创建默认自定义return的目录,这个目录虽然是默认的,但是默认并没有创建 :(

      mkdir /srv/salt/_returners

自定义reuters:

主要就是returner(ret) 这个函数的定义

cat /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()

同步到所有节点:

salt '*' saltutil.sync_returners

执行命令

salt '*' cmd.run 'ls /var' --return local_return

查看结果:

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

3fluent采集

客户端配置:

<source></source>
  type tail
  path /var/log/salt/returner
  pos_file /tmp/return_pos.log
  tag os.salt
  format /\"(?.*)\", \"(?\d+)\", (?.*), \"(?.*)\", (?.*)/
    type forward
    flush_interval 1s
        host 
        port 

服务端配置:

<source></source>
  type forward
  port 24224
  bind 0.0.0.0
  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

结果查询:

select * from salt_returns where success is 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 |
+------+----------------------+-----------------------------------------+---------------------+---------+---------+---------+
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What Are the Limitations of Using Views in MySQL?What Are the Limitations of Using Views in MySQL?May 14, 2025 am 12:10 AM

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

Securing Your MySQL Database: Adding Users and Granting PrivilegesSecuring Your MySQL Database: Adding Users and Granting PrivilegesMay 14, 2025 am 12:09 AM

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

What Factors Influence the Number of Triggers I Can Use in MySQL?What Factors Influence the Number of Triggers I Can Use in MySQL?May 14, 2025 am 12:08 AM

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

MySQL: Is it safe to store BLOB?MySQL: Is it safe to store BLOB?May 14, 2025 am 12:07 AM

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

MySQL: Adding a user through a PHP web interfaceMySQL: Adding a user through a PHP web interfaceMay 14, 2025 am 12:04 AM

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor