Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Anastasia Galkin
check-wp
Commits
18719f55
Commit
18719f55
authored
Jun 23, 2017
by
Anastasia Galkin
Browse files
formating log file, log directory specified
parent
e65002dd
Changes
3
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
18719f55
The
wp-
check script checks statistics for
a
wordpress instance for the time frame of 1 day and logs those into file with a timestamp.
The check
-wp
script checks statistics for wordpress instance
s
for the time frame of 1 day and logs those into file with a timestamp.
*
new users
*
new posts
*
new pages
**
Requirenments
For Centos:
```
yum install MySQL-python
```
Create the user and grant select privileges on the DB:
```
create user 'wp-check-user'@'your_server' identified by 'password';
grant select on wordpress_db.* to `wp-check-user`@`your_server`;
```
Let the check run every day at 5am
```
crontab -e
```
Insert
```
# check wordpress instances for news
0 5 * * * /usr/bin/python /opt/check-wp/check-wp.py
```
`
check-wp.py
View file @
18719f55
...
...
@@ -5,13 +5,13 @@ import MySQLdb
from
settings
import
*
log_name
=
''
+
time
.
strftime
(
"%Y%m%d_%H%M%S"
)
+
'_wordpress_stats.log'
log_name
=
LOG_DIR
+
time
.
strftime
(
"%Y%m%d_%H%M%S"
)
+
'_wordpress_stats.log'
logfile
=
open
(
log_name
,
"w"
)
# Open database connection
for
i
,
wp
in
WORDPRESS_DATABASES
.
items
():
logfile
.
write
(
"Wordpress: '{0}' "
.
format
(
i
)
+
'
\n
'
)
logfile
.
write
(
"Wordpress: '{0}' "
.
format
(
wp
[
'NAME'
])
)
nonews
=
True
db
=
MySQLdb
.
connect
(
wp
[
'HOST'
],
wp
[
'USER'
],
wp
[
'PASSWORD'
],
wp
[
'DATABASE'
])
...
...
@@ -25,6 +25,7 @@ for i, wp in WORDPRESS_DATABASES.items():
if
int
(
count
[
0
])
>
0
:
nonews
=
False
logfile
.
write
(
' '
+
wp
[
'URL'
]
+
'
\n
'
)
logfile
.
write
(
"{0} new {1}
\n
"
.
format
(
''
.
join
(
map
(
str
,
count
)),
j
))
logfile
.
write
(
stats
[
'header'
]
+
"
\n
"
)
cursor
.
execute
(
stats
[
'query'
])
...
...
@@ -33,9 +34,9 @@ for i, wp in WORDPRESS_DATABASES.items():
logfile
.
write
(
' | '
.
join
(
map
(
str
,
row
))
+
'
\n
'
)
if
nonews
:
logfile
.
write
(
'
Nothing new here.
'
)
logfile
.
write
(
'
....
\n
'
)
logfile
.
write
(
'
\n
'
)
logfile
.
write
(
'
\n
'
)
db
.
close
()
...
...
sample.settings.py
View file @
18719f55
LOG_DIR
=
''
WORDPRESS_DATABASES
=
{
'default'
:
{
'NAME'
:
''
,
'URL'
:
''
,
'USER'
:
''
,
'PASSWORD'
:
''
,
'HOST'
:
''
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment