forked from guohongze/adminset
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
监控平台system模块信息上传接口API agent多线程
- Loading branch information
Showing
8 changed files
with
97 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,8 @@ token = HPcWR7l4NJNJ | |
log_path = /var/opt/adminset/logs | ||
log_level = info | ||
|
||
[mongodb] | ||
ip = 127.0.0.1 | ||
port = 27017 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#! /usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
import json | ||
from lib.common import token_verify | ||
from pymongo import MongoClient | ||
from config.views import get_dir | ||
from django.shortcuts import HttpResponse | ||
import time | ||
from django.views.decorators.csrf import csrf_exempt | ||
|
||
|
||
@csrf_exempt | ||
def received_sys_info(request): | ||
iToken = get_dir("token") | ||
if request.method == 'POST': | ||
mongodb_ip = get_dir("mongodb_ip") | ||
mongodb_port = get_dir("mongodb_port") | ||
received_json_data = json.loads(request.body) | ||
# 验证token | ||
if received_json_data["token"] != iToken: | ||
print "forbidden your token error!!" | ||
return HttpResponse(status=403) | ||
hostname = received_json_data["hostname"] | ||
received_json_data['timestamp'] = int(time.time()) | ||
client = MongoClient(mongodb_ip, int(mongodb_port)) | ||
db = client.sys_info | ||
collection = db[hostname] | ||
collection.insert_one(received_json_data) | ||
return HttpResponse("Post the system Monitor Data to Server successfully!") | ||
else: | ||
return HttpResponse("Your push hava errors, Please Check your data!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters