$prescript = 'wget'; $prescriptparams = '--quiet'. ' --output-document=/tmp/$CL_VIDEO$.xml'. ' http://gdata.youtube.com/feeds/api/videos?q=$CL_VIDEO$&v=2'; $scriptpath = "/usr/bin"; $options = "prescript,supersmartpostscript"; @searches = ({ tag => '$CL_VIDEO$', logfile => '/tmp/$CL_VIDEO$.xml', criticalpatterns => ['statistics', 'rating', 'media:title'], options => "script,allyoucaneat", script => sub { my $line = $ENV{CHECK_LOGFILES_SERVICEOUTPUT}; if ($line =~ /viewCount='(\d+)'/) { $CHECK_LOGFILES_PRIVATESTATE->{views} = $1; } if ($line =~ /numDislikes='(\d+)'/) { $CHECK_LOGFILES_PRIVATESTATE->{dislikes} = $1; } if ($line =~ /numLikes='(\d+)'/) { $CHECK_LOGFILES_PRIVATESTATE->{likes} = $1; } if ($line =~ /<media:title.*?>(.*?)<\/media:title>/) { $CHECK_LOGFILES_PRIVATESTATE->{title} = $1; } }, }); $postscript = sub { my $video = $ENV{CHECK_LOGFILES_VIDEO}; my $state = $CHECK_LOGFILES_PRIVATESTATE->{$video}; my $title = exists $state->{title} ? $state->{title} : "(unknown)"; my $views = exists $state->{views} ? $state->{views} : 0; my $likes = exists $state->{likes} ? $state->{likes} : 0; my $dislikes = exists $state->{dislikes} ? $state->{dislikes} : 0; my $popularity = ($likes + $dislikes) ? $likes * 100 / ($likes + $dislikes) : 100; printf "%s was viewed %d times | %s=%d popularity=%.02f%%\n", $title, $views, $video, $views, $popularity; unlink '/tmp/'.$video.'.xml'; return 0; };