WordPress’s lastBuildDate in RSS Feed – gotcha’s

It has been ages since I wrote some technical stuff over here.

I recently stumbled into what apparently is a long-standing issue in WordPress, to the point that a lot of people decide to just implement their own, separate, RSS feed (there are a lot of articles out there on how to do that but I didn’t like such a solution).
The issue is that it doesn’t advance the ‘lastBuildDate’ field in the field often enough and we also didn’t like the logic that it uses to calculate it. In fact, by default, WordPress has logic to pull the last ‘modified’ date rather than the ‘published’ date of a post, then it also includes dates from comments… not what we needed since I am working for a news website where publication is almost always scheduled (which means the ‘modified’ date could be even a day older than the ‘publish’ date) and where comments are disabled!

More importantly, this was affecting how often Google actually processed their feed – not fast enough because it thought it was stale/not updated – and this severely impacted their chance to be found in Google News.

Here’s my solution (code to add to your functions.php or a custom plugin):

/* speed up feed cache */
add_filter( 'wp_feed_cache_transient_lifetime', create_function('$a', 'return 600;') );

/* overrides/changes the way 'lastBuildDate' is calculated for the standard wordpress RSS feed */
function my_lastpostmodified()
{
    global $wpdb;
    $add_seconds_server = date('Z');
    $lastDateSql = $wpdb->get_var("SELECT DATE_ADD(post_date_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1");
    $lastDate = date_create($lastDateSql);
    return $lastDate->format('r');
}

add_filter('get_lastpostmodified', 'my_lastpostmodified');
add_filter('get_feed_build_date', 'my_lastpostmodified');

Sources that helped me come up with this solution:

Death by right-click -> Delete ? Nope. PowerShell.

So at one stage I was testing the RSS reader capabilities of Outlook 2007, and I imported an OPML file with roughly 500 feeds! Of course I was NOT interested in reading ALL of them, and it was causing quite a bit of work to do on my machine to fetch them all and sync the content in my mailbox…

So I figured out it was possible to remove the subscription (from the Tools menu -> Account Settings -> RSS Feeds) but the folders were left there. Now, I didn’t want to have those 500 folders in my mailbox, and I did not even want to die by right-clicking, pressing “delete”, confirming…. all of this 500 times! No way.

So I wrote this little PowerShell script, I guess it *might* be helpful to someone at one stage, who knows ?

[System.Reflection.Assembly]::LoadWithPartialName(‘Microsoft.Office.Interop.Outlook’)
$oApp = New-Object -COM ‘Outlook.Application’
$rss = $oApp.GetNamespace(“MAPI”).GetDefaultFolder(“olFolderRssFeeds”)
forach ($folder in $rss.Folders)
{
$folder.Delete()
}

Please note that if you don’t have the Office Interop Assemblies installed on your machine, you can’t use the first line. As a result, you will have to change the third line hardcoding the number that represents the RSSFeeds folder, so it would become:

$rss = $oApp.GetNamespace(“MAPI”).GetDefaultFolder(25)

Note: I found out (later, of course) that there is a much more general post on this subject (that is, automating Outlook through PowerShell): http://www.leeholmes.com/blog/GettingThingsDoneOutlookTaskAutomationWithPowerShell.aspx

MOM 2005 Alerts to RSS feed

I am an RSS Addict, you know that.So I wanted an RSS Feed to show MOM Alerts. I have been thinking of it for a while, last year (or was it the year before?).
It seemed like a logical thing to me: alerts are created (and can be resolved – that is, expire), generally get sorted by the date and the time when they have been created, the look pretty much like a list. Also, many people like to receive mail notification when new alerts are generated.
So, if the alert can be sent to you (push), you could also get to it(pull).
Pretty much the same deal with receiving a mail or reading a newsgroup, or syndicating a feed.

At the time I looked around but it seemed like no one had something like this already done.
So I wrote a very simple RSS feed generator for MOM Alerts.
I did it quite an amount of time ago, just as an exercise.
Then, after a while, I figured out that the MOM 2005 Resource Kit had been updated to include such a utility!

Wow, I thought, they finally added what I have been thinking for a while. Might it be because I mentioned it on an private Mailing list ? Maybe. Maybe not. Who cares. Of course, if it is included in the resource kit it must be way cooler than the one I made, I though.
I really thought something along these lines, but never actually had the time to try it out.
I think I just sort of assumed it must have been cooler than the one I made, since it was part of an official package, while I am not a developer. So I basically forgot about the one I wrote, dismissing it as being crap without looking too much into it anymore.
Until today.
Today I actually tried to use the alert to RSS tool included in the resource kit, because a customer asked if there was any other way to get notified, other than receiving notification or using the console (or the console notifier).
So I looked at the resource kit’s Alert-to-RSS Utility.
My experience with it:
1) it is provided in source code form – which is ok if it was ALSO provided as source. Instead it is ONLY provided as source, and most admins don’t have Visual Studio installed or don’t know how to compile from the command line;
2) Even when they wanted to compile it, it includes a bug which makes it impossible to compile – solution in this newsgroup discussion;
3) if you don’t want to mess about with code since you are using a resource Kit tool (as opposed to something present in the SDK) you can even get it already compiled by someone from somewhere on the net, but that choice is about trust.

Anyway, one way or another, after it is finally set up…. surprise surprise!!!
It does NOT show a LIST of alerts (as I was expecting).
It shows a summary of how many alerts you have. basically it is an RSS feed made of a single item, and this single item tells you how many alerts you have. What is one supposed to do with such a SUMMARY? IMHO, it is useless the way it is. It is even worse than one of those feed that only contains the excerpt of the article, rather than the full article.
Knowing that I have 7 critical errors and 5 warning without actually knowing ANYTHING of them is pointless.
It might be useful for a manager, but not for a sysadmin, at least.

So I thought my version, even if coded crap, might be useful to someone because it gives you a list of alerts (those that are not resolved) and each one of them tells you the description of the alert, the machine tat generated it, and includes links to the actual alert in the web console, so you can click, go there, and start troubleshooting from within your aggregator!
My code does this. Anyway, since I am a crap coder, since I wrote it in only fifteen minutes more than a year ago, and since I don’t have time to fix it and make it nicer… it has several issues, and could be improved in a million ways, in particular for the following aspects:

  1. is currently depends on the SDK Database views – it could use the MOM Server API’s or the webservice instead;
  2. it uses SQL Security to connect to the DB – by default MOM does not allow this – it is suggested for the SQL instance hosting “OnePoint” to only use Windows Integrated Authentication.. so to make my code work you have to switch back to Mixed mode, and create a login in SQL that has permission to read the database. This is due to the fact that I’ve coded this in five minutes and I don’t know how to use delegation – if I was able to use delegation, I would… so that the end user accessing IIS would be the one connecting to the DB. If anybody wants to teach me how to do this, I will be most grateful.
  3. it could accept parameters as URL variables, so to filter out only events for a specific machine, or a specific resolution state, etc etc
  4. At present it uses RSS.Net to generate the feed. It could made independent from it, but I don’t really see why, and I quite like that library.

The code is just an ASP.Net page and its codebehind, no need to compile, but of course you need to change a couple of lines to match your webconsole address.
Also, you need to get RSS.NET and copy its library (RSS.Net.dll) in the /bin subfolder of the website directory where you place the RSSFeed generator page. I see that I wrote this with version 0.86, but any version should do, really.

Here is what it will look like:

AlertToRSS

And here’s the code of the page (two files):

Default.aspx

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

Default.aspx.cs

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using Rss;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string webconsoleaddress = “http://192.168.0.222:1272/AlertDetail.aspx?v=a&sid=” // must change to match your address

// Inizializza il Feed
RssChannel rssChannel = new RssChannel();
rssChannel.Title = “MOM Alerts”
rssChannel.PubDate = DateTime.Now;
rssChannel.Link = new Uri(“http://192.168.0.222:1272/rss/”); // must change to match your address
rssChannel.LastBuildDate = DateTime.Now;
rssChannel.Description = “Contains the latest Alerts”

// query – you might want to change the severity
string mySelectQuery = “SELECT ComputerName, Name, Severity, TimeRaised, RepeatCount, GUID FROM dbo.SDKAlertView WHERE Severity > 10 AND ResolutionState < 255”

// SQL Connection – must change SQL server, user name and password
SqlConnection conn = new SqlConnection(“Data Source=192.168.0.222;Initial Catalog=OnePoint;User ID=rss;Password=rss”);
SqlDataReader rdr = null;

try
{
conn.Open();
SqlCommand cmd = new SqlCommand(mySelectQuery, conn);
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
RssItem rssItem = new RssItem();
string titleField = rdr[1].ToString();
rssItem.Title = titleField;
string url = webconsoleaddress + rdr[5];
rssItem.Link = new Uri(url.ToString());
string description = “<![CDATA[ <p><a xhref=\”” + rssItem.Link + “\”>” + rdr[1] + ” </a></p><br>” + “<br>Computer: ” + rdr[0] + “<br>Repeat Count: ” + rdr[4] + “<BR>Original ALert Time: ” + rdr[3];
rssItem.Description = description;
rssChannel.Items.Add(rssItem);
}

// Finalizza il feed
RssFeed rssFeed = new RssFeed();
rssFeed.Channels.Add(rssChannel);
Response.ContentType = “text/xml”
Response.ExpiresAbsolute = DateTime.MinValue;
rssFeed.Write(Response.OutputStream);
}
finally
{
if (rdr != null)
{
rdr.Close();
}

if (conn != null)
{
conn.Close();
}
}
}
}

Of aggregators, and the Geek in me

As usual, Dare speaks a pearl of wisdom here:

“[…] I didn’t think subscribing to feeds in a conventional aggregator would ever become used by a widespread percentage of the population. Subscribing to feeds seems cool to geeks because it solves a geek problem; having too many sources of information to keep track of and optimizing how this is done. The average person doesn’t think it’s cool to be able to keep track of 10 – 20 websites a day using a some tool because they aren’t interested in 10 – 20 websites on a daily basis in the first place. […]”

In fact, this reminds me I am a geek, as I could not stay up to date with the load of things I wanna read, withuot his wonderful RSS Bandit.

RSS Thoughts

I am not quite sure I understand why Roberdan has posted this http://blogs.msdn.com/roberdan/comments/502576.aspx very basic explanation of what an RSS feed is.
Probably to start educating the masses, and preparing that amount of business people to WHAT RSS is…. preparing them to actually use the format when (soon) it will finally be mainstream with Office 12 and IE7…. to this regard Scoble says “[…]don’t underestimate the effect of Outlook 12’s support of RSS here. It’ll bring millions of new businesspeople into the RSS world. This is HUGE.[…]”. http://scobleizer.wordpress.com/2005/12/22/outlook-pm-talks-about-upcoming-rss-integration/
And he’s right of course. I keep forgetting RSS is not in the mainstream yet. “My” idea of what is mainstream is mostly polluted by my geeky visions…

But coming back to the point – that was Roberdan’s post – I wanted to comment there, but for some reason I am not able to do so (even though it does not seem to be a problem with http://blogs.msdn.com, as I can comment to my blog there… I don’t know)… so I will comment here (hoping he sees the pingback). The comment I wanted to write is this that follows (in Italian):

——————————————

Bisognerebbe inoltre menzionare che anche le liste di SharePoint stesso si possono ri-pubblicare in formato RSS per farle fruire ad altri reader. Per il momento questa possibilita’ non c’e’ nativamente in SharePoint, ma si puo’ attivare installando una web part quale “BlogWave”
http://blogs.msdn.com/asanto/archive/2004/08/22/218625.aspx oppure quella messa a disposizione da BlueDogLimited:
http://www.bluedoglimited.com/Downloads/pages/SyndicationGenerator.aspx

Anch’io ho scritto un simile oggetto che genera feed a partire da liste di siti realizzati con SharePoint, qualora non si avesse la possibilita’ di installare webparts sul proprio sharepoint, e lo faccio da remoto, estraendo le informazioni dal Web Service si SPS.

Invece per fortuna lo SharePoint “futuro” che uscira’, avra’ questa possibilita’ nativamente:
http://radio.weblogs.com/0001011/2005/09/17.html#a11176

RSS a sloppy format, but successful

http://www.onlamp.com/pub/a/onlamp/2005/04/22/bosworth.html

RSS is a sloppy format.
That why is working so well and succeeding.
Wow, cool, like it happened for the web.
Yep, that’s also a sloppy format, in fact, I agree on this one.
Sloppy or not… who really cares ?
Best things in life are usually SIMPLE.

What is happening with RSS feeds in building a logical network of links between content, which is more efficient than the web it runs on.

I like that.
I like that a lot.

A couple of years ago I in fact pushed my friends of a couple of sites to push their information with RSS feeds.

On this website we use first or third-party tools that store small files (cookie) on your device. Cookies are normally used to allow the site to run properly (technical cookies), to generate navigation usage reports (statistics cookies) and to suitable advertise our services/products (profiling cookies). We can directly use technical cookies, but you have the right to choose whether or not to enable statistical and profiling cookies. Enabling these cookies, you help us to offer you a better experience. Cookie and Privacy policy