line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Wiki::Toolkit::Plugin::Ping; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
45021
|
use strict; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
94
|
|
4
|
2
|
|
|
2
|
|
13
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
6668
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
15
|
use vars qw( @ISA $VERSION ); |
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
129
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
2265
|
use Wiki::Toolkit::Plugin; |
|
2
|
|
|
|
|
884
|
|
|
2
|
|
|
|
|
58
|
|
9
|
2
|
|
|
2
|
|
5317
|
use LWP; |
|
2
|
|
|
|
|
188536
|
|
|
2
|
|
|
|
|
70
|
|
10
|
2
|
|
|
2
|
|
25
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1307
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
@ISA = qw( Wiki::Toolkit::Plugin ); |
13
|
|
|
|
|
|
|
$VERSION = '0.03'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# Set things up |
17
|
|
|
|
|
|
|
sub new { |
18
|
4
|
|
|
4
|
1
|
1544
|
my $class = shift; |
19
|
4
|
|
|
|
|
12
|
my %args = @_; |
20
|
|
|
|
|
|
|
|
21
|
4
|
|
|
|
|
6
|
my $self = {}; |
22
|
4
|
|
|
|
|
9
|
bless $self, $class; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Get list of services |
25
|
4
|
100
|
|
|
|
11
|
unless($args{services}) { |
26
|
1
|
|
|
|
|
8
|
$self->{services} = {}; |
27
|
1
|
|
|
|
|
3
|
return $self; |
28
|
|
|
|
|
|
|
} |
29
|
3
|
|
|
|
|
4
|
my %services = %{$args{services}}; |
|
3
|
|
|
|
|
10
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Get node -> URL mapping |
32
|
3
|
100
|
|
|
|
9
|
unless($args{node_to_url}) { |
33
|
1
|
|
|
|
|
12
|
die("Must supply 'node_to_url;"); |
34
|
|
|
|
|
|
|
} |
35
|
2
|
50
|
|
|
|
10
|
unless($args{node_to_url} =~ /\$node/) { |
36
|
0
|
|
|
|
|
0
|
die("node_to_url '$args{node_to_url}' must contain \$node"); |
37
|
|
|
|
|
|
|
} |
38
|
2
|
|
|
|
|
5
|
$self->{node_to_url} = $args{node_to_url}; |
39
|
2
|
|
33
|
|
|
11
|
$self->{agent} = $args{agent} || "Wiki::Toolkit::Plugin::Ping $VERSION"; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Check the services |
43
|
2
|
|
|
|
|
7
|
foreach my $service (keys %services) { |
44
|
3
|
|
|
|
|
5
|
my $url = $services{$service}; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Make valid |
47
|
3
|
50
|
|
|
|
11
|
unless($url =~ /^http:\/\//) { |
48
|
0
|
|
|
|
|
0
|
$url = "http://".$url; |
49
|
0
|
|
|
|
|
0
|
$services{$service} = $url; |
50
|
|
|
|
|
|
|
} |
51
|
3
|
100
|
|
|
|
12
|
unless($url =~ /\$url/) { |
52
|
1
|
|
|
|
|
10
|
die("For $service, URL '$url' didn't contain \$url anywhere\n"); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Save |
57
|
1
|
|
|
|
|
3
|
$self->{services} = \%services; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Done setup |
60
|
1
|
|
|
|
|
5
|
return $self; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# Return our list of services, in case anyone's interested |
64
|
|
|
|
|
|
|
sub services { |
65
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
66
|
0
|
|
|
|
|
|
return %{$self->{services}}; |
|
0
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Define our post_write plugin, which does the ping |
70
|
|
|
|
|
|
|
# Happens in another thread, to stop it slowing things down |
71
|
|
|
|
|
|
|
sub post_write { |
72
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
73
|
0
|
0
|
|
|
|
|
unless(keys %{$self->{services}}) { return; } |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my %args = @_; |
76
|
0
|
|
|
|
|
|
my ($node,$node_id,$version,$content,$metadata) = |
77
|
|
|
|
|
|
|
@args{ qw( node node_id version content metadata ) }; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# Spawn a new thread |
80
|
0
|
|
|
|
|
|
my $pid = fork(); |
81
|
0
|
0
|
|
|
|
|
if($pid) { |
82
|
|
|
|
|
|
|
# We're the main thread, return now |
83
|
0
|
|
|
|
|
|
return; |
84
|
|
|
|
|
|
|
} else { |
85
|
|
|
|
|
|
|
# We're the child, do the work |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Apply the formatter escaping on the node name, if there's one |
88
|
0
|
0
|
|
|
|
|
if($self->formatter) { |
89
|
|
|
|
|
|
|
# Eval, in case the formatter doesn't support node name escaping |
90
|
0
|
|
|
|
|
|
eval { |
91
|
0
|
|
|
|
|
|
$node = $self->formatter->node_name_to_node_param($node); |
92
|
|
|
|
|
|
|
}; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# What's the URL of the node? |
96
|
0
|
|
|
|
|
|
my $node_url = $self->{node_to_url}; |
97
|
0
|
|
|
|
|
|
$node_url =~ s/\$node/$node/; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# Get a LWP instance |
100
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
101
|
0
|
|
|
|
|
|
$ua->agent($self->{agent}); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# Ping each service |
104
|
0
|
|
|
|
|
|
foreach my $service (keys %{$self->{services}}) { |
|
0
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# Build the ping URL |
106
|
0
|
|
|
|
|
|
my $ping_url = $self->{services}->{$service}; |
107
|
0
|
|
|
|
|
|
$ping_url =~ s/\$url/$node_url/; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# Ping |
110
|
0
|
|
|
|
|
|
my $req = HTTP::Request->new(GET => $ping_url); |
111
|
0
|
|
|
|
|
|
my $res = $ua->request($req); |
112
|
0
|
0
|
|
|
|
|
unless($res->is_success) { |
113
|
0
|
|
|
|
|
|
warn("Error pinging $service: $res->status_line"); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# All done, close the thread |
118
|
0
|
|
|
|
|
|
exit; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# Returns a list of well known services |
123
|
|
|
|
|
|
|
sub well_known { |
124
|
|
|
|
|
|
|
return ( |
125
|
0
|
|
|
0
|
0
|
|
pingerati => 'http://pingerati.net/ping/$url', |
126
|
|
|
|
|
|
|
geourl => 'http://geourl.org/ping/?p=$url', |
127
|
|
|
|
|
|
|
); |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
131
|
|
|
|
|
|
|
__END__ |