Thursday, July 26, 2012

Creating SharePoint 2010 reports with Javascript and Twitter Bootstrap

SharePoint 2010 is a decent CMS out there from Microsoft.  Great for customized document storage, customized data lists, and of course Office Web Apps for cross-browser web based viewers/editors (word, excel, powerpoint, visio, etc).  SharePoint 2010 can also be extended to open source technologies rather easily with its REST services in order to create customized HTML reports rather than viewing through the clunky ribbon interface in SharePoint itself.

In this presentation, I will use NodeJS, Express, Jade, coffee-script, and Twitter's Bootstrap to construct a simple list report generator that page breaks on every item.  We will pretend that the SharePoint 2010 data is a custom list with three required columns and two optional columns that may not contain data:  Title (string), Content (rich text), and Feedback (rich text), TextArea1, TextArea2.  The last two are obviously the optional columns.

Imagine that this custom list contains a lot of text in each column.  Viewing this in SharePoint would show it as a grid, with each associated property listed horizontally (think spreadsheet).  There would be much scrolling or resizing of the browser.  Why cant we view this data like a book or a white paper?  That is what I intend to accomplish in this presentation.

First of all, you'll need to pick up all the tools.  I am using Node 0.8.3 with the following modules:  Express (3.0.0beta7), Jade (0.27.0), coffee-script (1.3.3), and request (2.9.203).  All of the modules are on npm.  See here for instructions on running coffee-script from the command line.

Next, pick up the latest bootstrap and its javascript plugins.  Finally go get jQuery.

$ mkdir reportGenerator
$ cd reportGenerator
$ mkdir public routes views

Now that we have our public folder, lets put the client side stuff in there.

$ mv ~/Downloads/bootstrap ./public
$ mv ~/Downloads/jQuery.min.js ./public/bootstrap/js

Lets setup our web server.

$ vim

Now we need to create the route depends on.

$ vim ./routes/

Cool.  So this route renders a Jade template.  Lets make the layout and index templates.

$ vim ./views/layout.jade

$ vim ./views/index.jade

Now that the templates are done, we are ready to rock.  Start it up

$ coffee

Print to PDF.  Look at that!  A nice report generated with page breaks on each main topic (item) based on SharePoint 2010 data in a simple yet expressive way.

Saturday, July 21, 2012

Installing coffee-script cli

Today I will be updating my box to the latest nodejs and after doing so, installing the coffee-script command line interface which allows for coffee-script to be run on such things as crontab, init.d, or even nagios (see other post).  I will also be installing nodemon which will act as a daemon for my coffee-script web applications.  Nodemon will watch for changes and restart the application if it finds any, which is pretty neat.

$ wget
$ tar zxvf node-v0.8.3.tar.gz

$ cd node-v0.8.3

$ ./configure

{ 'target_defaults': { 'cflags': [],
                       'default_configuration': 'Release',
                       'defines': [],
                       'include_dirs': [],
                       'libraries': []},
  'variables': { 'host_arch': 'x64',
                 'node_install_npm': 'true',
                 'node_install_waf': 'true',
                 'node_prefix': '',
                 'node_shared_openssl': 'false',
                 'node_shared_v8': 'false',
                 'node_shared_zlib': 'false',
                 'node_use_dtrace': 'false',
                 'node_use_etw': 'false',
                 'node_use_openssl': 'true',
                 'target_arch': 'x64',
                 'v8_no_strict_aliasing': 1,
                 'v8_use_snapshot': 'true'}}
creating  ./config.gypi
creating  ./

$ make
$ sudo make install
$ sudo npm install -g coffee-script
$ sudo npm install -g nodemon

Saturday, July 14, 2012

Sending custom Nagios notification emails with coffeescript

Lets imagine for a second that you are using Nagios to monitor systems and services.  Nagios can send you notifications upon events, but the default email notification command is kind of boring.

Lets spice it up with coffeescript!


define contact{
        contact_name                    mike
        alias                           Mike Kunze
        service_notification_period     24x7
        host_notification_period        24x7
        service_notification_options    w,u,c,r
        host_notification_options       d,r
        service_notification_commands   notify-service-with-nodejs
        host_notification_commands      notify-host-by-email

define command {
    command_name    notify-service-with-nodejs


This script will be executed by nagios and will contain the macros provided by the nagios command.