forked from andaok/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrab_send.py
More file actions
92 lines (83 loc) · 3.42 KB
/
rab_send.py
File metadata and controls
92 lines (83 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# =============================================================================
# FileName: rab_send.py
# Desc: 2015-15/10/12:上午9:37
# Author: 苦咖啡
# Email: voilet@qq.com
# HomePage: http://blog.kukafei520.net
# History:
# =============================================================================
import pika
import time
import json
credentials = pika.PlainCredentials("admin", "voilet_850225")
# credentials = pika.PlainCredentials("cmdb", "964e486c24cfd234ca9aa63bdc3f3fab")
conn_params = pika.ConnectionParameters("192.168.111.101", credentials=credentials)
connection = pika.BlockingConnection(conn_params)
channel = connection.channel()
channel.exchange_declare(exchange='auth.user', exchange_type='direct')
channel.basic_publish(exchange='auth.user',
routing_key="user",
body=json.dumps({'ip': '192.168.121.18', 'type': 1, 'user': 'songxs', 'auth': 0,
'node': 'salt_test', "uid": 3002, "gid": 1001,
'ssh_key': "asdfasdfsadfasdfsadf"}))
# print " [x] Sent %r:%r" % (routing_key, message)
# time.sleep(10)
connection.close()
# import requests
# requests.packages.urllib3.disable_warnings()
# url = "https://192.168.8.80/login"
# headers = {
# 'CustomUser-agent': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)',
# "Accept": "application/json",
# }
# data = {"username": "salt", "password": "992a15aecbcf5727df775c45a35738cf",
# "eauth": "pam"}
# s = requests.post(url, headers=headers, data=data, verify=False)
# t = s.json()
# salt_token = [i["token"] for i in t["return"]]
# salt_token = salt_token[0]
# print salt_token
# headers["X-Auth-Token"] = salt_token
# # test = {"remove": True, "force": True}
# # salt_data = {"client": "local", "fun": "user.delete", "tgt": "salt_test", "arg": {"remove": True, "force": True}, "voilet1"}
#
# salt_data = {"client": "local", "fun": "user.delete", "tgt": "salt_test", "arg": ["remove=True", "force=True", "voilet1"]}
# # salt_data = {"client": "local", "fun": "user.delete", "tgt": "salt_test", "arg": "voilet1" }
# sl = requests.post("https://192.168.8.80/", headers=headers, data=salt_data, verify=False)
# print sl.text
#
# credentials = pika.PlainCredentials("admin", "voilet_850225")
# conn_params = pika.ConnectionParameters("192.168.111.101", credentials=credentials)
# connection = pika.BlockingConnection(conn_params)
#
# channel = connection.channel()
# channel.exchange_declare(exchange='auth.user', type='direct')
# channel.basic_publish(exchange='auth.user',
# routing_key="user",
# body="hello")
#
# result = channel.queue_declare(exclusive=True)
# queue_name = result.method.queue
#
# severities = sys.argv[1:]
# if not severities:
# print >> sys.stderr, "Usage: %s [info] [warning] [error]" % \
# (sys.argv[0],)
# sys.exit(1)
#
# for severity in severities:
# channel.queue_bind(exchange='auth.user',
# queue="user",
# routing_key=severity)
#
# print ' [*] Waiting for logs. To exit press CTRL+C'
# def callback(ch, method, properties, body):
# print " [x] %r:%r" % (method.routing_key, body,)
#
# channel.basic_consume(callback,
# queue="user",
# no_ack=True)
#
# channel.start_consuming()