postgresql plpythonu例子
以下代码仅作为参考之用
select md5, crc32, record->'UserModerAnalysis'->'base_info'->'file_malware' as file_malware
from reports
CREATE OR REPLACE FUNCTION py_get_file_malware(record TEXT)
RETURNS TEXT
AS $$
# pl/python functioin body
import json
plpy.notice('type of record is', type(record))
# plpy.notice('import json')
# plpy.notice('begin to loads()')
#if 'json' in SD:
# json = SD['json']
#else:
# import json
# SD['json'] = json
obj = json.loads(record)
plpy.notice('UserModerAnalysis = %s'%(str(obj['UserModerAnalysis'])))
try:
file_malware = obj['UserModerAnalysis']['base_info']['file_malware']
except Exception, e:
#plpy.error(record)
plpy.notice('ERROR!')
file_malware = ''
return file_malware
$$ LANGUAGE plpythonu
select md5, crc32, py_get_file_malware(record::TEXT)
from reports
limit 2
-- create table summary
CREATE TABLE summary_file_malware
(
description character varying(10) NOT NULL,
count integer,
CONSTRAINT summary_file_malware_pkey PRIMARY KEY (description)
)
DROP FUNCTION calculate_file_malware()
CREATE OR REPLACE FUNCTION calculate_file_malware()
RETURNS trigger AS $$
plpy.notice('calculate_file_malware invoked')
import json
event = TD['event']
if event == 'INSERT':
plpy.notice('insert triggered')
elif event == 'UPDATE':
plpy.notice('update triggered')
# parse parameter
old_obj = json.loads(TD['old']['record'])
new_obj = json.loads(TD['new']['record'])
plpy.notice('old = %s, new = %s'%(old_obj['UserModerAnalysis']['base_info']['file_malware'],
new_obj['UserModerAnalysis']['base_info']['file_malware']))
# sub old
try:
plpy.notice('begin')
plan = plpy.prepare('SELECT * FROM summary_file_malware WHERE description = $1', ['text'])
old_value = old_obj['UserModerAnalysis']['base_info']['file_malware']
plpy.notice("old_value = " + old_value)
rv = plpy.execute(plan, [old_value], 1)
old_count = int(rv[0]['count'])
plpy.notice('old_count = %s'%(old_count))
plan = plpy.prepare('UPDATE summary_file_malware SET count = $1 WHERE description = $2', ['int', 'text'])
plpy.execute(plan, [old_count - 1, old_value])
except Exception, e:
plpy.notice('exception occured, exception msg = '+str(e))
# add new
try:
plan = plpy.prepare('SELECT * FROM summary_file_malware WHERE description = $1', ['text'])
old_value = new_obj['UserModerAnalysis']['base_info']['file_malware']
rv = plpy.execute(plan, [old_value], 1)
old_count = int(rv[0]['count'])
plpy.notice('old_count = %s'%(old_count))
plan = plpy.prepare('UPDATE summary_file_malware SET count = $1 WHERE description = $2', ['int', 'text'])
plpy.execute(plan, [old_count + 1, old_value])
except Exception, e:
plpy.notice('exception occured, exception msg = '+str(e))
elif event == 'DELETE':
plpy.notice('delete triggered')
elif event == 'TRUNCATE':
plpy.notice('trancate triggered')
else:
plpy.notice('unknow event, event = ', event)
$$ LANGUAGE plpythonu
DROP TRIGGER IF EXISTS calculate on reports;
CREATE TRIGGER calculate AFTER UPDATE OF record
ON reports
FOR EACH ROW
EXECUTE PROCEDURE calculate_file_malware ();
SELECT * FROM summary_file_malware WHERE description ='OK'
INSERT INTO summary_file_malware VALUES('OK', 0)
UPDATE reports SET record = '{"Name": "000BD3A69E56CD5E8D998FEDA8EF3CA6.CCD2FFE1", "UserModerAnalysis": {"base_info": {"file_malware": "YES"}, "file_monitor": [], "virusname": null, "danger_behavior": [], "relation": {"processtree": [{"processid": "608", "process": "000BD3A69E56CD5E8D998FEDA8EF3CA6.CCD2FFE1", "module": "", "parentid": 0, "relationtype": "Root", "id": 1}]}, "other_behavior": [], "network_monitor": [], "process_monitor": [], "reg_monitor": []}, "KernelModelAnalysis": {"MaliciousActives": {"000BD3A69E56CD5E8D998FEDA8EF3CA6.CCD2FFE1": {"MemoryOperations": {}, "FileOperations": {"CREATE_FILE.DROP_PE_TO_SYSTEM_DIR": [{"COMMENT": "Create_File_In_SystemDirectory", "DETAILS": {"file_path": "c:\\windows\\.exe"}, "LEVEL": "LEVEL_3"}]}, "NetworkOperations": {}, "ProcessOperations": {}, "RegistryOperations": {}, "OtherOperations": {}}}, "ProcessFamily": {"000BD3A69E56CD5E8D998FEDA8EF3CA6.CCD2FFE1": {"Parent_Process": "", "Command_Line": "", "Type_Created": "Root"}}, "ProcessActives": {"000BD3A69E56CD5E8D998FEDA8EF3CA6.CCD2FFE1": {"MemoryOperations": {}, "FileOperations": {"DELETE_FILE": [{"COMMENT": "Delete_File_Found", "DETAILS": {"file_path": "C:\\DOCUME~1\\autoer\\LOCALS~1\\Temp\\~DFCCF6.tmp"}, "LEVEL": "LEVEL_2"}], "CREATE_FILE": [{"COMMENT": "Create_File_Found", "DETAILS": {"file_path": "C:\\DOCUME~1\\autoer\\LOCALS~1\\Temp\\~DFCCF6.tmp"}, "LEVEL": "LEVEL_2"}]}, "NetworkOperations": {}, "ProcessOperations": {}, "RegistryOperations": {"SET_KEY_VALUE": [{"COMMENT": "Set_Key_Value_Found", "DETAILS": {"value": "Drive", "type": "REG_SZ", "name": "BaseClass", "key": "HKEY_USERS\\S-1-5-21-1708537768-287218729-1177238915-1003\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\MountPoints2\\{7fb46850-baea-11e1-9890-806d6172696f}"}, "LEVEL": "LEVEL_2"}]}, "OtherOperations": {}}}, "TimeOfReportCreated": "2013-06-03 11:25:25:724 +0800", "Summary": ["CREATE_FILE", "CREATE_FILE.DROP_PE_TO_SYSTEM_DIR", "DELETE_FILE", "SET_KEY_VALUE"], "FileName": "000BD3A69E56CD5E8D998FEDA8EF3CA6.CCD2FFE1"}, "Result": "Success", "Time": "2013-06-03 11:25:25:724 +0800", "DESCRIPTION": "\u64cd\u4f5c\u6210\u529f\u5b8c\u6210\u3002"}' WHERE md5 = '000BD3A69E56CD5E8D998FEDA8EF3CA6' and crc32 = 'CCD2FFE1'
select * from summary_file_malware
postgresql plpythonu例子的更多相关文章
- .NET Core开发日志——Entity Framework与PostgreSQL
Entity Framework在.NET Core中被命名为Entity Framework Core.虽然一般会用于对SQL Server数据库进行数据操作,但其实它还支持其它数据库,这里就以Po ...
- PostGIS(解压版)安装
1.软件下载 postgresql-9.6.1-1-windows-x64-binaries.zip https://www.postgresql.org/download/windows/ post ...
- sqlmap用户手册 | WooYun知识库
sqlmap用户手册 说明:本文为转载,对原文中一些明显的拼写错误进行修正,并标注对自己有用的信息. 原文:http://drops.wooyun.org/tips/143 ============ ...
- sqlmap用户手册
http://192.168.136.131/sqlmap/mysql/get_int.php?id=1 当给sqlmap这么一个url的时候,它会: 1.判断可注入的参数2.判断可以用那种SQL注入 ...
- sqlmap用户手册详解(转)
http://url/sqlmap/mysql/get_int.php?id=1 当给sqlmap这么一个url的时候,它会: 1.判断可注入的参数 2.判断可以用那种SQL注入技术来注入 3.识别出 ...
- OpenLDAP使用疑惑解答及使用Java完成LDAP身份认证
导读 LDAP(轻量级目录访问协议,Lightweight Directory Access Protocol)是实现提供被称为目录服务的信息服务.目录服务是一种特殊的数据库系统,其专门针对读取,浏览 ...
- sqlmap
http://192.168.136.131/sqlmap/mysql/get_int.php?id=1 当给sqlmap这么一个url的时候,它会: 1.判断可注入的参数 2.判断可以用那种SQL注 ...
- 【转】sqlmap用户手册
http://192.168.136.131/sqlmap/mysql/get_int.php?id=1 当给sqlmap这么一个url的时候,它会: 1.判断可注入的参数2.判断可以用那种SQL注入 ...
- sqlmap用户手册 [详细]
当给sqlmap这么一个url的时候,它会: 1.判断可注入的参数 2.判断可以用那种SQL注入技术来注入 3.识别出哪种数据库 4.根据用户选择,读取哪些数据 sqlmap支持五种不同的注入模式: ...
随机推荐
- HTML <area> 标签 带有可点击区域的图像映射(图像映射指的是带有可点击区域的图像)
例子: <img src="planets.gif" width="145" height="126" alt="Plane ...
- php部分---include()与require()的区别、empty()与isset is_null的区别与用法详解
include()与require()的用途是完全一样的,不一定非得哪个放在最前面哪个放在中间.他们最根本的区别在于错误处理的方式不一样. 1.处理错误的方式: require()一个文件存在错误的话 ...
- leetcode 136. Single Number ----- java
Given an array of integers, every element appears twice except for one. Find that single one. Note:Y ...
- HDU 2717 Catch That Cow --- BFS
HDU 2717 题目大意:在x坐标上,农夫在n,牛在k.农夫每次可以移动到n-1, n+1, n*2的点.求最少到达k的步数. 思路:从起点开始,分别按x-1,x+1,2*x三个方向进行BFS,最先 ...
- ABB机器人添加串口模块后无法使用的解决办法
[环境] ABB机器人1520,IRC5,RobotWare5.6,Win10 64bits,RobotStudio6.0 [过程和表现] 由于项目需要和机器人通信,DeviceNet又不能满足要求, ...
- const 常引用
常类型是指使用类型修饰符 const 说明的类型,常类型的变量或对象的值是不能被更新的. 这篇主要说常引用.常引用是指所引用的对象不能被更新. 在实际应用中,常引用往往用来作为函数的形参,这样的参数称 ...
- GCC编译器
详见<gcc中文手册> 编译过程 预处理器cpp 编译器gcc 汇编器as 链接器linker file.c -------------> file.i ----------- ...
- jquery轻松操作CSS样式
$(this).click(function(){ if($(this).hasClass(“zxx_fri_on”)){ $(this).removeClass(“zxx_fri_on”); ...
- UserDefault的使用,保存小数据到本地-iOS
//保持到本地数据 NSArray *array=@[@"234",@"sdfe"]; NSUserDefaults *userDefault=[NSUserD ...
- 给OCR文字识别软件添加图像的方法
ABBYY FineReader 12是一款OCR图片文字识别软件,而且强大的它现在还可使用快速扫描窗口中的快速打开.扫描并保存为图像或任务自动化任务,在没有进行预处理和OCR的ABBYY FineR ...