Saltstack Event Practice

Source: Internet
Author: User
Tags glob saltstack


Today to the official website A Salt event test example to revise and summarize, in order to better understand the use of the event, the following tests are based on the official website of the steps to do



Test 1:

Write a Python script on the master side first:


Import salt.utils.eventevent = salt.utils.event.MasterEvent ('/var/run/salt/master ') for eachevent in Event.iter_ Events (full=true): Print eachevent print "------"


Also open a terminal, and then execute the command:


Salt ' * ' test.ping


The results are as follows:


{' tag ':  ' 20150227111546144547 ',  ' data ':  {' _stamp ':  ' 2015-02-27t11:15:46.145663 ',  ' Minions ':  [' Gs-ssh '}}------{' tag ':  ' new_job ',  ' data ':  {' tgt_type ':  ' glob ',  ' Jid ':  ' 20150227111546144547 ',  ' TGT ':  ' * ',  ' _stamp ':  ' 2015-02-27t11:15:46.147099 ',  ' User ':  ' root ',  ' arg ': [],  ' fun ':  ' test.ping ',  ' Minions ':  [' Gs-ssh '}}------ {' tag ':  ' salt/job/20150227111546144547/new ',  ' data ':  {' tgt_type ':  ' glob ',  ' Jid ':   ' 20150227111546144547 ',  ' TGT ':  ' * ',  ' _stamp ':  ' 2015-02-27t11:15:46.148181 ',  ' User ':  ' root ',  ' arg ': [],  ' fun ':  ' test.ping ',  ' Minions ':  [' Gs-ssh '}}------ {' tag ':  ' 20150227111546144547 ',  ' data ':  {' Fun_args ': [],  ' Jid ':  ' 20150227111546144547 ',  ' return ': true,  ' Retcode ': 0,  ' success ': true,  ' cmd ' :  ' _return ',  ' _stamp ':   ' 2015-02-27t11:15:46.216332 ',  ' fun ':  ' test.ping ',  ' id ':  ' gs-ssh '}}------{' tag ':  ' salt/ Job/20150227111546144547/ret/gs-ssh ',  ' data ':  {' Fun_args ': [],  ' Jid ':  ' 20150227111546144547 ',  ' return ': true,  ' Retcode ': 0,  ' success ': true,  ' cmd ' :  ' _return ',  ' _stamp ':  ' 2015-02-27t11:15:46.218268 ',  ' fun ':  ' test.ping ',  ' id ':   ' GS-SSH '}------


from the output results, for the tag is only Jid, the official note in the source code is "Old DUP event", presumably to be compatible with the older event system (0.17.0 version of the event system has been updated), this time do not do it. The tag of the assigned task corresponds to New_job, and when the task is issued, the master side is doomed in the event that those minions need to run (minions in the corresponding data dictionary). If the tag containssalt/job/the word and the data dictionaryreturnIs true to indicate that the event is the result returned by Minion.


Test 2:

Tasks that exceed the timeout setting (default is 5 seconds):


Execute command:

Salt ' * ' cmd.run ' sleep 6; echo Hello World '


The results are as follows:

{' tag ':  ' 20150227113729719091 ',  ' data ':  {' _stamp ':  ' 2015-02-27t11:37:29.720087 ',  ' Minions ':  [' Gs-ssh '}}------{' tag ':  ' new_job ',  ' data ':  {' tgt_type ':  ' glob ',  ' Jid ':  ' 20150227113729719091 ',  ' tgt ':  ' gs* ',  ' _stamp ':  ' 2015-02-27t11:37:29.722007 ',   ' user ':  ' root ',  ' arg ':  [' sleep 6; echo hello world '],  ' fun ':   ' Cmd.run ',  ' Minions ':  [' Gs-ssh '}}------{' tag ':  ' salt/job/20150227113729719091/new ',   ' data ':  {' tgt_type ':  ' glob ',  ' Jid ':  ' ' 20150227113729719091 ',  ' tgt ':  ' gs* ',   ' _stamp ':  ' 2015-02-27t11:37:29.723067 ',  ' user ':  ' root ',  ' arg ':  [' sleep 6;  echo hello world '],  ' fun ':  ' Cmd.run ',  ' Minions ':  [' Gs-ssh '}}------{' tag ':   ' 20150227113734739021 ',  ' data ':  {' _stamp ':  ' 2015-02-27t11:37:34.739470 ',  ' Minions ':  [' Gs-ssh '}}------{' tag ':  ' new_job ',  ' data ':  {' tgt_type ':  ' glob ',  ' Jid ':  ' 20150227113734739021 ',  ' TGT ':  ' gs* ',  ' _stamp ':  ' 2015-02-27t11:37:34.740245 ',  ' user ':  ' root ',  ' arg ':  [' 20150227113729719091 '],  ' fun ':  ' saltutil.find_job ',  ' Minions ':  [' Gs-ssh ']}}------{ ' Tag ':  ' salt/job/20150227113734739021/new ',  ' data ':  {' tgt_type ':  ' glob ',  ' Jid ':  ' 20150227113734739021 ',  ' tgt ':  ' gs* ',  ' _stamp ':  ' 2015-02-27t11:37:34.740498 ',  ' user ':   ' root ',  ' arg ':  [' 20150227113729719091 '],  ' fun ':  ' saltutil.find_job ',  ' Minions ':  [' Gs-ssh '}}------{' tag ':  ' 20150227113734739021 ',  ' data ':  {' Fun_args ':  [' 20150227113729719091 '],  ' Jid ':  ' 20150227113734739021 ',  ' return ':  {' tgt_type ':  ' glob ',   ' Jid ':  ' 20150227113729719091 ',  ' tgt ':  ' gs* ',  ' pid ': 24526,  ' ret ':  ',   ' user ':  ' root ',   ' Arg ':  [' sleep 6; echo hello world '],  ' fun ':  ' cmd.run '},  ' retcode ':  0,  ' success ': true,  ' cmd ':  ' _return ',  ' _stamp ':  ' 2015-02-27t11 : 37:34.806601 ',  ' fun ':  ' saltutil.find_job ',  ' id ':  ' gs-ssh '}}------{' tag ':  ' salt/job/ 20150227113734739021/ret/gs-ssh ',  ' data ':  {' Fun_args ':  [' 20150227113729719091 '],  ' Jid ':   ' 20150227113734739021 ',  ' return ':  {' tgt_type ':  ' glob ',  ' Jid ':  ' 20150227113729719091 ',  ' tgt ':  ' gs* ',  ' pid ': 24526,  ' ret ':  ' ',  ' user ':  ' Root ',  ' arg ':  [' sleep 6; echo hello world '],  ' fun ':  ' Cmd.run '},  ' Retcode ': 0,  ' success ': true,  ' cmd ':  ' _return ',  ' _stamp ':  ' 2015-02-27t11 : 37:34.806801 ',  ' fun ':  ' saltutil.find_job ',  ' id ':  ' gs-ssh '}}------{' tag ':  ' 20150227113729719091 ',  ' data ':  {' Fun_args ':  [' sleep 6; echo hello world '],  ' Jid ':  ' 20150227113729719091 ',  ' Return ':  ' Hello world ',  ' retcode ': 0,  ' success ': true,  ' cmd ':  ' _return ',  ' _stamp ':  ' 2015-02-27t11:37:35.814281 ',  ' fun ':  ' cmd.run ',  ' id ':  ' gs-ssh '}}--- ---{' tag ':  ' salt/job/20150227113729719091/ret/gs-ssh ',  ' data ':  {' Fun_args ':  [' sleep 6 ;  echo hello world '],  ' Jid ':  ' 20150227113729719091 ',  ' return ':  ' hello  World ',  ' retcode ': 0,  ' success ': true,  ' cmd ':  ' _return ',  ' _stamp ':  ' 2015-02-27t11:37:35.814502 ',  ' fun ':  ' cmd.run ',  ' id ':  ' gs-ssh '}}------


In addition to the previous test.ping testing a similar output, you can see the tag asNew_job5 Seconds after the event is generated, it automatically generates a fun value ofSaltutil.find_job, whose arg is the event of the previously New_job Jid. Then Minion returns the fun value that was run beforeCmd.runthe corresponding running information (PID and other information, has ensured that the task is being executed).


Salt corresponds to the processing mechanism:

1.master after the command is issued, if all Minion return the result within the timeout time set, then exit directly.

2. If timeout time is reached (default is 5s ), there is still a minion that does not return a result, it automatically triggers a Saltutil.find_job task, go to all Minion to query whether the task is executing.

3. If Minion returns a task that is currently executing, wait for a new timeout period, exit if all Minion return the result,  

wait until all minion return the result. If the period is triggered Saltutil.find_job when Minion does not return the execution status of the task, and the result is not returned, it is considered that the Minion problem will output " Minion did not return "(Can be queried by the salt-v parameter).


from this mechanism, it can be known that if the Minion can not return the results of the situation, for some scenarios such as large or minion high load , when the set timeout time, the automatic triggeringSaltutil.find_jobtask, and Minion does not start running the task before it is issued. Causes Master to consider "Minion did not return" directly. You need to increase the value of timeout at this point (you can modify the timeout option in master's configuration file)


and because Master automatically triggersSaltutil.find_jobtasks, and this task is also credited to the event system, so for third-party systems such as Halite, you'll find a lot ofSaltutil.find_joboperation, this is a normal phenomenon, no need to process.


Summarize:

Salt provides a powerful event system that can easily be inserted into the event system, capturing the current salt's running state, and easily extending the salt function.




This article is from the "ohgenlong16300blog.com" blog, make sure to keep this source http://ohgenlong16300.blog.51cto.com/499130/1615636

Saltstack Event Practice

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.