Articles of python

系统日志filter通过标签或文本包含自己的文件

我需要从我的Python应用程序login到syslog。 在系统日志我想过滤消息从我的应用程序自己的文件。 我正在使用Debian 8.3。 我的rsyslog规则: # cat /etc/rsyslog.d/99-MyLog.conf :syslogtag, isequal, "MyLog" /var/log/mylog.log :msg, contains, "MyLog" /var/log/mylog.log 和我的python脚本/tmp/test.py : import logging.handlers my_logger = logging.getLogger('MyLog') my_logger.setLevel(logging.INFO) handler = logging.handlers.SysLogHandler(address = '/dev/log') formatter = logging.Formatter('MyLog: %(message)s') handler.setFormatter(formatter) my_logger.addHandler(handler) my_logger.info("Test Log 123") 如果发送消息到系统日志: # logger -t MyLog "Test from bash logger" # logger "MyLog Test from bash logger" # […]

用LDAPconfigurationdjango

我已经使用python应用程序成功地configuration了LDAP,使用db/model.py这些语句: from gluon.contrib.login_methods.ldap_auth import ldap_auth auth.settings.login_methods = [ldap_auth(mode='ad', server='ldap.example.com', base_dn='dc=example,dc=com')] 我正在尝试与Django相同,但是我在网上看到的所有说明都相当复杂。 什么Django相当于我的web2py LDAP设置? 有没有简单的方法来debugging到Django服务器控制台的LDAP连接过程? 这是我所尝试的: import ldap from django_auth_ldap.config import LDAPSearch, GroupOfNamesType # LDAP Configuration AUTH_LDAP_SERVER_URI = "ldap://ldap.example.com" AUTH_LDAP_BIND_DN = "" AUTH_LDAP_BIND_PASSWORD = "" AUTH_LDAP_USER_DN_TEMPLATE = "uid=%(user)s,ou=users,dc=example,dc=com" # group names: #AUTH_LDAP_GROUP_SEARCH = LDAPSearch("ou=groups,dc=example,dc=com", # ldap.SCOPE_SUBTREE, "(objectClass=groupOfNames)" # ) #AUTH_LDAP_GROUP_TYPE = GroupOfNamesType() #AUTH_LDAP_FIND_GROUP_PERMS = True #AUTH_LDAP_CACHE_GROUPS […]

在不同于AWS Lamda(新加坡)的区域(孟买)创build实例的AMI

我正在使用AWS Lamda为我的ec2 prod实例每天创buildAMI。 我在孟买地区的所有基础设施,但是aws不支持孟买地区的Lamdafunction。 所以,我select了新加坡地区来设立Lamda。 我暂停了create-AMI和cleanup-ami这两个链接来创build和删除ami的保留期限。 不过,如果我在新加坡地区也有代码中指定的标签的情况下,这个工作。 我在这里的问题是,我怎么能够在孟买地区取得实例并创造艾米(拉姆达在新加坡地区)

在Shinken中没有收到设定时间的更新时,将状态设置为警告

我目前正在与Shinkenbuild立监控的过程。 对于一些检查,我使用webservice模块来接收传入的状态更新。 但是,如果上次更新正常,然后设备/链接以阻止进一步更新的方式失败,会发生什么情况? 我的问题是 – 是否有任何方法来自动设置警告状态时更新没有收到设定的时间,如60秒?

syslog-ng不能识别“python”关键字

我正在尝试使用Syslog-ng,以便将消息转发到python目标。 但是,我不断收到“错误parsing目标,目标插件python找不到…”消息。 我完全按照这个教程。 https://syslog-ng.gitbooks.io/getting-started/content/chapters/chapter_5/section_1.html 从我可以收集的关键字“java”和“python”需要Syslog-ng 3.7+。 我已经从3.5.6升级到了。 我也将提供的configuration文件@version:3.7更改为@version:3.8,这是我从示例中更改的唯一一个。 任何想法为什么Syslog ng不能识别我的configuration文件中的关键字“python”? 这是提供的脚本。 @version: 3.7 @include "scl.conf" source s_local { system(); internal(); }; destination python_to_file { python( class("betterpythonexample.TextDestination") on-error("fallback-to-string") value-pairs(scope(everything)) ); }; log { source(s_local); destination(python_to_file); }; 这是示例中的python代码。 class LogDestination(object): def open(self): """Open a connection to the target service""" return True def close(self): """Close the connection to […]

显示/没有www的索引,与www正常工作

我正在使用Python,Flask和Apache,而且我被卡住了。 当我尝试访问使用www的mywebsite,它工作正常。 然而,当我删除www,该网站正在显示“索引/”下一个空的文件列表。 我读过所有可能的解决scheme,在我的情况下没有任何作用。 我正在使用WSGI,这意味着DocumentRoot是不相关的,因为我使用WSGIScriptAliasvariables。 按照指示使用ServerAlias – 不起作用。 我已经在我的DNS选项中设置了2个独立的Alogging,都指向相同的IP。 当我用www平网站,没有它,相同的IP地址显示 <VirtualHost *:80> ServerName mysite.com ServerAlias www.mysite.com WSGIScriptAlias / /var/www/mysite/mysite.wsgi <Directory /var/www/mysite/mysite/> Order allow,deny Allow from all </Directory> Alias /static /var/www/mysite/mysite/app/static <Directory /var/www/mysite/mysite/app/static/> Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined … </VirtualHost> 有任何想法吗? 这是“apachectl -S”命令的输出: VirtualHost configuration: *:80 is a […]

如何通过代理升级版本点子?

为我的任务需要安装pywin32包。 Python只能通过代理安装新的包。 pip –proxy http://<username>:<password>@<hostname>:<port> install pywin32 但是安装结束错误 Collecting pywin32 Could not find a version that satisfies the requirement pywin32 (from versions : ) No matching distribution found for pywin32 You are using pip version 8.1.2, however version 9.0.1 is available. You should consider upgrading via the 'python -m pip install –upgrade pip' comm and. […]

重新启动nginx和gunicorn没有sudo

我可以运行systemctl restart gunicorn && systemctl restart nginx没有sudo ? 目前我得到: 出:authentication是需要重新加载'gunicorn.service'。 out:身份validation:myuser 输出:密码: # coding: utf-8 from fabric.api import * from fabric.colors import green, red def production(): env.host_string = '159.xxx.xxx.xx' env.user = 'myuser' path = "/home/myuser/myproject/myproject" print(red("Beginning Deploy:")) with cd(path): with prefix('. /home/myuser/myproject/myenv/bin/activate'): run("pwd") print(green("Pulling master from git…")) run("git pull") print(green("Migrate the database…")) run("python3 manage.py migrate") […]

CentOS 7 / Apache / mod_wsgi – UnicodeDecodeError:'ascii'编解码器无法解码2727位的字节0xc2:序号不在范围内(128)

我已经使用mod_wsgi在Apache(httpd)中部署了Python Web应用程序(使用金字塔)。 启动Apache服务后,当我们向Web应用程序发出http请求时,会发生下面的错误(来自Apache日志)… [Mon Feb 06 16:38:55.980119 2017] [wsgi:error] [pid 16031] [remote 172.16.13.1:204] mod_wsgi (pid=16031): Target WSGI script '/usr/local/lb/ve32/src/LBGenerator/lbgenerator.wsgi' cannot be loaded as Python module. [Mon Feb 06 16:38:55.980205 2017] [wsgi:error] [pid 16031] [remote 172.16.13.1:204] mod_wsgi (pid=16031): Exception occurred processing WSGI script '/usr/local/lb/ve32/src/LBGenerator/lbgenerator.wsgi'. Traceback (most recent call last): File "/usr/local/lb/ve32/src/LBGenerator/lbgenerator.wsgi", line 1, in <module> from […]

如何在厨师的Linux上创build一个后台服务?

我有一个Python脚本,我在ubuntu主机上使用screen执行,我想用一个Chef食谱把它变成适当的后台服务。 python脚本启动一个SMTP服务器,丢弃所有的电子邮件(一个“黑洞”服务器,用于testing),然后调用python的asyncore.loop()永远运行。 我怎么把这变成一个厨师的食谱? 我正在使用cookbook_file资源上传我的Python脚本,我知道我需要使用service 资源来启动服务,但是我不确定如何实际创build服务。 我需要写一个文件到/etc/init.d或/etc/systemd来在操作系统级创build服务,或者是否有一些我可以调用的Chef recipe / resource来为我创build一个后台服务,给定的命令? 我使用的厨师11.18.12 ,不能升级,所以这就排除了一些食谱(如runit ),需要12+。 主机操作系统是Ubuntu 14.04.3 。 这是迄今为止我所得到的: include_recipe 'apt' include_recipe 'python' # the python script to run as a background service cookbook_file '/usr/local/bin/smtp_server_blackhole.py' do source 'smtp_blackhole_server.py' owner 'root' group 'root' mode '0755' end # the init.d file which defines the service? Not sure about this part… […]