一个urllib的post方法的使用例子

#!/usr/bin/python

import re

import os

import urllib

try:

import simplejson

except ImportError:

os.popen(‘yum install python-simplejson -y‘)

try:

import pycurl

except ImportError:

os.popen(‘yum install python-pycurl -y‘)

def buffer_line(monitor_log):

buf = open("/etc/sae/rdc_buffer.txt").read()

bytes=os.popen(‘wc -c /data0/logs/rdcmonitor/%s‘%monitor_log).read().split(" ")[0]

if int(bytes) < int(buf):

return 0

else:

return int(re.findall("^\d*", buf)[0])

def set_last_pos(pos):

open("/etc/sae/rdc_buffer.txt", "w").write(str(pos))

def monitor_work(monitor_log):

fh=open(‘/data0/logs/rdcmonitor/%s‘%monitor_log,‘r‘)

fh.seek(buffer_line(monitor_log))

content=fh.read()

new_total_lines=len(content)+buffer_line(monitor_log)

set_last_pos(new_total_lines)

new_lines=content.split("\n")

return new_lines

def monitor_work_1(content):

dict_1={‘service‘:‘rdc_monitor‘,‘checkpoint‘:‘rdc_monitor_log‘,‘title‘:content,‘content‘:content,‘cluster‘:‘public‘,‘grade‘:‘2‘}

params = urllib.urlencode(dict_1)

urllib.urlopen(‘http://alert.sae.sina.com.cn/new/‘,params)

#cc = pycurl.Curl()

#cc.setopt(cc.URL,‘http://alert.sae.sina.com.cn/new/?service=rdc_monitor&checkpoint=rdc_monitor_log&title=%s&content=%s&cluster=public&grade=2‘%(title,content)

)

#cc.perform()

if __name__ == ‘__main__‘:

log=os.popen("ls -lrt /data0/logs/rdcmonitor/|awk ‘END{print}‘").read()

print log

now_log=log.split(‘\n‘)[0].split()[-1]

value=monitor_work(now_log)

list_1=[]

host_ip=os.popen(‘hostname‘).read().split(‘\n‘)[0]

for i in value:

print i

if i.find(‘error‘) >= 0:

print i

list_1.append(i)

print list_1

if len(list_1) > 0:

date_json=simplejson.dumps(list_1)

print ‘error‘

list_len=len(list_1)

monitor_work_1(host_ip+‘_rdc_log_error:‘+date_json)

时间: 2024-08-27 06:55:56

一个urllib的post方法的使用例子的相关文章

android 调用前摄像头进行拍照的方法及完整例子

android调用camera时,可以自己写一个activity,赋上相关参数,打开前camera就可以了: 需要申请的permission,在AndroidManifest.xml中添加: <uses-permission android:name="android.permission.CAMERA" /> <uses-feature android:name="android.hardware.camera" android:required

Java反射机制demo(五)—获得并调用一个类中的方法

这个demo在使用反射机制操作属性之前,主要原因是因为在.class文件字节码中,方法排在属性的前面. 1,获得一个类中的方法 先看一下方法和运行结果.获取所有的方法使用Class类中getMethos()方法. 待获取的类: 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 package

MVC4方法行为过滤器例子(用户登录)

在Model文件夹下添加一个类MyActionFilterAttribute继承于ActionFilterAttribute: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace MvcValidateDemo.Models { //AllowMultiple = true:允许多个标签同时都起作用 [Attribu

反射获取一个类的私有方法

今天在刷面试题的时候,发现一个题目是编写程序通过反射获取一个类的私有方法,因为之前学反射的时候也学的浅,没有考虑到这样的事情.今天敲了一下,虽然也就是那么几行代码,还是磕磕绊绊的,最后终于搞定了,这里总结一下 Java反射得到一个类的私有方法 获得私有方法的流程是 (1)获取目标类 (2)获取目标方法 Method method=clazz.getDeclaredMethod(name);//可以调用类中的所有方法(不包括父类中继承的方法) Method method=clazz.getMeth

PHP加载另一个文件类的方法

加载另一个文件类的方法 当前文件下有a.php 和b.php,想要在class b中引入class a <?php    class a    {        public $name = 'zhouqi';        public function say()        {            echo 'hello '.$this->name;        }    } <?php    class b    {        //require('a.php'); 错

[ jquery 过滤器next(expr) ] 此方法用于在选择器的基础之上搜索被选元素的后一个同级元素,此方法参数只能传递表达式,无法传递其他类型

此方法用于在选择器的基础之上搜索被选元素的后一个同级元素,此方法参数只能传递表达式,无法传递其他类型: 实例: <html lang='zh-cn'> <head> <title>Insert you title</title> <meta http-equiv='description' content='this is my page'> <meta http-equiv='keywords' content='keyword1,key

每天一个设计模式-5 工厂方法模式

每天一个设计模式-5 工厂方法模式 1.模式定义 定义一个用于创建对象的接口,让子类决定实例化那一个类,Factory Method使一个类的实例化延迟到其子类. 2.工厂方法模式解决问题的思路 工厂方法模式需要接口对象,那就定义一个方法来创建这个接口对象(工厂方法):可是事实上它自己是不知道如何创建这个接口对象的,没有关系,定义成抽象方法让子类来实现就可以了:这样这个对象本身就可以只是面向接口编程,而无需关心到底如何创建接口对象了. 3.实际问题 实现一个导出数据的功能,客户选择数据的导出格式

java中如何实现一个优美的equals方法

java中的任何类都从老祖宗Object中集成了equals方法,在编程实践中应用使用equals方法判断两个对象是否相同的场景无处不在,所以我们在实现自己的类是必须重写出一个优美的equals方法. 首先让我们来看看java语言规范中对equals方法的说明,一个equals方法应当满足如下几个特性: 自反性,对任何一个非空的引用x,x.equals(x)必须返回true: 对称性,对任何引用x和y来说,如果x.equals(y)返回true,那么y.equals(x)也必须返回true: 传

.net又一个生成缩略图的方法,不变形

生成缩略图是一个十分常用功能,找到了一个方法,重写部分代码,实用又好用,.net又一个生成缩略图的方法,不变形 1 /// <summary> 2 /// 为图片生成缩略图 by 何问起 3 /// </summary> 4 /// <param name="phyPath">原图片的路径</param> 5 /// <param name="width">缩略图宽</param> 6 ///