How do I get the cloud foundry services usage - cloud-foundry

I have deployed some services in cloud foundry. I need to get the usage of all my services. I referred to this document.
I have tried to explore the above documentation in python . I tried the below program:
import sys
import json
import requests
import cf_api
from flask import Flask
from flask_cors import CORS, cross_origin
from getpass import getpass
def apps():
cloud_controller_url = 'https://app-usage.run.pivotal.io/system_report/service_usages'
username='user'
password='pass'
response=''
print('-----apps-----')
print('Authenticating with UAA...')
cc = cf_api.new_cloud_controller(
cloud_controller_url,
client_id='cf', # the ``cf`` command uses this client and the secret below
client_secret='',
username=username,
password=password,
)
print('Login OK!')
print('----------')
print('Searching for applications...')
req = cc.request('/system_report/service_usages')
resources_list = cc.get_all_resources(req)
f = open ("cfServices.json", "w")
print(json.dumps(resources_list))
f.write(json.dumps(resources_list))
apps()
I also tried to explore it in postman. I got 404 error.
I am expecting results. this is the sample expecting output which is provided in cloud foundry documentation:
{
"report_time": "2017-05-11 18:29:14 UTC",
"monthly_service_reports": [
{
"service_name": "fake-service-0507f1fd-2340-49a6-9d43-a347a5f5f6be",
"service_guid": "177dcfde-cd51-4058-bd86-b98015c295f5",
"usages": [
{
"month": 1,
"year": 2017,
"duration_in_hours": 0,
"average_instances": 0,
"maximum_instances": 0
},
{
"month": 2,
"year": 2017,
"duration_in_hours": 0,
"average_instances": 0,
"maximum_instances": 0
},
{
"month": 3,
"year": 2017,
"duration_in_hours": 4.182222222222227,
"average_instances": 0,
"maximum_instances": 2
},
{
"month": 4,
"year": 2017,
"duration_in_hours": 2176.962222222186,
"average_instances": 3,
"maximum_instances": 7
},
{
"month": 5,
"year": 2017,
"duration_in_hours": 385.61388888888854,
"average_instances": 1.5,
"maximum_instances": 3
}
],
"plans": [
{
"usages": [
{
"month": 1,
"year": 2017,
"duration_in_hours": 0,
"average_instances": 0,
"maximum_instances": 0
},
{
"month": 2,
"year": 2017,
"duration_in_hours": 0,
"average_instances": 0,
"maximum_instances": 0
},
{
"month": 3,
"year": 2017,
"duration_in_hours": 4.182222222222227,
"average_instances": 0,
"maximum_instances": 2
},
{
"month": 4,
"year": 2017,
"duration_in_hours": 1465.6388888888941,
"average_instances": 2,
"maximum_instances": 5
},
{
"month": 5,
"year": 2017,
"duration_in_hours": 385.61388888888854,
"average_instances": 1.5,
"maximum_instances": 3
}
],
"service_plan_name": "fake-plan",
"service_plan_guid": "ac09f607-f4e5-4807-af16-e95856061bd7"
}

i believe this api is for PAS owner who deploy PCF dev, and the PCF web services might not allow you to view that kind of information as it doesnot asking for ORG information
But i have something for you ,
you can use this api for each service you are using for fetching some of the information you want
REQUEST: [2019-01-28T22:58:19+05:30]
GET /v2/services/c72eba27-c3f6-4ccb-b2fb-0a7e8ce0a25 HTTP/1.1
Host: api.run.pivotal.io
Accept: application/json
Authorization: [PRIVATE DATA HIDDEN]
User-Agent: cf/6.37.0+a40009753.2018-05-25 (go1.9.6; amd64 windows)
RESPONSE: [2019-01-28T22:58:19+05:30]
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 1619
Content-Type: application/json;charset=utf-8
Date: Mon, 28 Jan 2019 17:28:18 GMT
Server: nginx
X-Content-Type-Options: nosniff
X-Ratelimit-Limit: 20000
X-Ratelimit-Remaining: 19941
X-Ratelimit-Reset: 1548699889
X-Vcap-Request-Id: 87b81068-f777-45a8-46ff-a116d449bd49::d4a02e66-208b-40c4-a9b7-c4afdcc9ffce
{
"entity": {
"active": true,
"bindable": true,
"bindings_retrievable": false,
"description": "Fully managed MongoDB-as-a-Service",
"documentation_url": null,
"extra": "{\n \"displayName\": \"mLab\",\n \"imageUrl\": \"https://d3bql97l1ytoxn.cloudfront.net/app_resources/5819/thumbs_64/img2243331358186927838.png\",\n \"longDescription\": \"mLab is a fully managed MongoDB Database-as-a-Service (DBaaS)\\nplatform that automates the operational aspects of running MongoDB in\\nthe cloud.\",\n \"providerDisplayName\": \"mLab\",\n \"documentationUrl\": \"http://docs.run.pivotal.io/marketplace/services/mlab.html\",\n \"supportUrl\": \"https://support.mlab.com/\"\n}",
"info_url": null,
"instances_retrievable": false,
"label": "mlab",
"long_description": null,
"plan_updateable": false,
"provider": null,
"requires": null,
"service_broker_guid": "bb6733db-3bdc-4d6d-c5a-63e9bbc1f4de",
"service_broker_name": "appdirect",
"service_plans_url": "/v2/services/c72eba27-c3f6-4cb-b2fb-0a74e8ce0a25/service_plans",
"tags": [
"Cloud Databases",
"Developer Tools",
"Web-based",
"Data Store",
"document",
"Windows",
"Security",
"IT Management",
"mongodb",
"Mac"
],
"unique_id": "6213a86a-ae52-11e3-ac06-22000a1dd446",
"url": null,
"version": null
},
"metadata": {
"created_at": "2015-01-19T21:16:29Z",
"guid": "c72eba27-c3f6-4ccb-b2fb-0a74e8ce0a25",
"updated_at": "2018-11-26T21:50:43Z",
"url": "/v2/services/c72eba27-c3f6-4ccb-b2fb-0a7e8ce0a25"
}
}
Hope this helps you

Related

Can we send multiple data in a single metric using aws cloudwatch cli?

Is there a way to send multiple data in a single metric using aws cloudwatch cli.
Have you tried specifying a json object and putting multiple items within that list?
i.e.
aws cloudwatch put-metric-data --namespace "Usage Metrics" --metric-data file://metric.json
Where metric.json is something like:
[
{
"MetricName": "Metric1",
"Timestamp": "Wednesday, November 2, 2013 8:28:20 AM",
"Value": 0.50,
"Unit": "Count"
},
{
"MetricName": Metric2,
"Timestamp": "Wednesday, November 2, 2013 8:28:20 AM",
"Value": 1,
"Unit": "Count"
},
{
"MetricName": "Metric 2",
"Timestamp": "Wednesday, November 2, 2013 8:29:20 AM",
"Value": 5,
"Unit": "Count"
}
]
if you need to send multiple values for one metric, something like:
[
{
"MetricName": "Metric1",
"Timestamp": "Wednesday, November 2, 2013 8:28:20 AM",
"Values": [0.50,2,3,5.1],
"Unit": "Count"
}
]
or
[
{
"MetricName": "Metric1",
"Timestamp": "Wednesday, November 2, 2013 8:28:20 AM",
"StatisticValues": {
"SampleCount": 8,
"Sum": 18,
"Minimum": 2.3,
"Maximum": 2.7
},
"Unit": "None"
}
]

Google Line Chart set value for no data to 0

I want integrate a google line chart on my raspberry pi terminal to show some statistics about my coffee consumption. If my json have got no value for a date, the line chart should set the value to 0. At the moment, dates with no values have got the value of the day before. Any ideas?
I have used this configuration:
let options = {
hAxis: {
format: 'd.M.yy',
gridlines: {count: 15},
},
vAxis: {
title: 'Cups of Coffee',
},
colors: ['#34495e'],
interpolateNulls : true
};
Dates with no value are not displayed in my json. For example: no entry for the date 3.6.2017 Here is the json:
[{
"_id": {
"year": 2017,
"month": 6,
"day": 9,
"action": "Coffee made"
},
"createdAt": "2017-06-09T06:41:50.904Z",
"count": 1
},
{
"_id": {
"year": 2017,
"month": 6,
"day": 8,
"action": "Coffee made"
},
"createdAt": "2017-06-08T05:44:04.081Z",
"count": 1
},
{
"_id": {
"year": 2017,
"month": 6,
"day": 7,
"action": "Coffee made"
},
"createdAt": "2017-06-07T06:10:01.713Z",
"count": 4
},
{
"_id": {
"year": 2017,
"month": 6,
"day": 6,
"action": "Coffee made"
},
"createdAt": "2017-06-06T05:52:09.775Z",
"count": 2
},
{
"_id": {
"year": 2017,
"month": 6,
"day": 2,
"action": "Coffee made"
},
"createdAt": "2017-06-02T06:03:47.243Z",
"count": 1
},
{
"_id": {
"year": 2017,
"month": 6,
"day": 1,
"action": "Coffee made"
},
"createdAt": "2017-06-01T05:37:31.399Z",
"count": 1
},
{
"_id": {
"year": 2017,
"month": 5,
"day": 31,
"action": "Coffee made"
},
"createdAt": "2017-05-31T05:18:49.220Z",
"count": 1
}
]
Current line chart output (The values of date 2. Jun to 5. June should be 0)
just need to add a row for the missing dates...
use data table method getFilteredRows to check data for a certain day
see following working snippet...
the json is loaded, then starting with the min date in the data,
and ending with the current date, each day is checked for data
if now rows are found, one is added with value of 0
google.charts.load('current', {
callback: function () {
drawChart();
window.addEventListener('resize', drawChart, false);
},
packages:['corechart', 'table']
});
function drawChart() {
var jsonData = [{
"_id": {
"year": 2017,
"month": 6,
"day": 9,
"action": "Coffee made"
},
"createdAt": "2017-06-09T06:41:50.904Z",
"count": 1
},
{
"_id": {
"year": 2017,
"month": 6,
"day": 8,
"action": "Coffee made"
},
"createdAt": "2017-06-08T05:44:04.081Z",
"count": 1
},
{
"_id": {
"year": 2017,
"month": 6,
"day": 7,
"action": "Coffee made"
},
"createdAt": "2017-06-07T06:10:01.713Z",
"count": 4
},
{
"_id": {
"year": 2017,
"month": 6,
"day": 6,
"action": "Coffee made"
},
"createdAt": "2017-06-06T05:52:09.775Z",
"count": 2
},
{
"_id": {
"year": 2017,
"month": 6,
"day": 2,
"action": "Coffee made"
},
"createdAt": "2017-06-02T06:03:47.243Z",
"count": 1
},
{
"_id": {
"year": 2017,
"month": 6,
"day": 1,
"action": "Coffee made"
},
"createdAt": "2017-06-01T05:37:31.399Z",
"count": 1
},
{
"_id": {
"year": 2017,
"month": 5,
"day": 31,
"action": "Coffee made"
},
"createdAt": "2017-05-31T05:18:49.220Z",
"count": 1
}
];
var datePattern = 'd.M.yy';
var formatDate = new google.visualization.DateFormat({
pattern: datePattern
});
var dataTable = new google.visualization.DataTable({
"cols": [
{"label": "Date", "type": "date"},
{"label": "Cups of Coffee", "type":"number"}
]
});
jsonData.forEach(function (row) {
dataTable.addRow([
new Date(row.createdAt),
row.count
]);
});
var startDate = dataTable.getColumnRange(0).min;
var endDate = new Date();
var oneDay = (1000 * 60 * 60 * 24);
for (var i = startDate.getTime(); i < endDate.getTime(); i = i + oneDay) {
var coffeeData = dataTable.getFilteredRows([{
column: 0,
test: function (value, row, column, table) {
var coffeeDate = formatDate.formatValue(table.getValue(row, column));
var testDate = formatDate.formatValue(new Date(i));
return (coffeeDate === testDate);
}
}]);
if (coffeeData.length === 0) {
dataTable.addRow([
new Date(i),
0
]);
}
}
dataTable.sort({column: 0});
var chartLine = new google.visualization.ChartWrapper({
chartType: 'LineChart',
containerId: 'chart',
dataTable: dataTable,
options: {
theme: 'material',
legend: {
position: 'none',
},
chartArea: {
top: 12,
right: 12,
bottom: 48,
left: 48,
height: '100%',
width: '100%'
},
colors: ['#34495e'],
hAxis: {
format: datePattern,
gridlines: {
count: 15
},
},
pointSize: 4,
vAxis: {
title: 'Cups of Coffee',
}
}
});
chartLine.draw();
}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart"></div>

What are examples of "other" page story types in the Facebook Graph API

When I make a request to get a break down for a day/week/month of the page stories, I get something like:
{
"data": [
{
"name": "page_stories_by_story_type",
"period": "day",
"values": [
{
"value": {
"checkin": 3,
"page post": 102,
"other": 1835,
"fan": 1233,
"user post": 0,
"question": 0,
"coupon": 0,
"event": 0,
"mention": 0
},
"end_time": "2016-11-02T07:00:00+0000"
},
....
]
}
}
What I can't figure out is what kind of story falls into "other"?

Can I get RabbitMq connection id from my Python/kombu client?

When I run this command:
rabbitmqctl list_connections pid
I get output like the following:
<rabbit#my_box.2.1234.0>
<rabbit#my_box.2.1235.0>
Is there a way to read this pid from my kombu client?
RabbitMQ does not expose this kind of internal details through AMQP.
You can get many informations about connections using the management plugin and its REST API. Here is an example:
// JSON returned by http://localhost:15672/api/connections
// ...
{
"connected_at": 1458292870638,
"client_properties":
{
"product": "RabbitMQ",
"copyright": "Copyright (c) 2007-2016 Pivotal Software, Inc.",
"capabilities":
{
"exchange_exchange_bindings": true,
"connection.blocked": true,
"authentication_failure_close": true,
"basic.nack": true,
"publisher_confirms": true,
"consumer_cancel_notify": true
},
"information": "Licensed under the MPL. See http://www.rabbitmq.com/",
"version": "0.0.0",
"platform": "Java"
},
"channel_max": 0,
"frame_max": 131072,
"timeout": 60,
"vhost": "/",
"user": "guest",
"protocol": "AMQP 0-9-1",
"ssl_hash": null,
"ssl_cipher": null,
"ssl_key_exchange": null,
"ssl_protocol": null,
"auth_mechanism": "PLAIN",
"peer_cert_validity": null,
"peer_cert_issuer": null,
"peer_cert_subject": null,
"ssl": false,
"peer_host": "127.0.0.1",
"host": "127.0.0.1",
"peer_port": 54872,
"port": 5672,
"name": "127.0.0.1:54872 -> 127.0.0.1:5672",
"node": "rabbit#localhost",
"type": "network",
"channels": 1,
"state": "running",
"send_pend": 0,
"send_cnt": 108973,
"recv_cnt": 99426,
"recv_oct_details":
{
"rate": 288892.8
},
"recv_oct": 5540646,
"send_oct_details":
{
"rate": 1912389.8
},
"send_oct": 36669998
},
// ...
However, PIDs are not exposed either through this mechanism.

JSON formatting error using Boost JSON parser

I'm attempting to use Boost to read a JSON file from my Firefox configuration folder called sessionstore.js, where the information on the current/last Firefox session is saved for purposes of recovery. I've written a program based on the XML-based tutorial from the Boost website, simply swapping out the XML parts for the JSON parts, which can be seen below
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/foreach.hpp>
#include <string>
#include <set>
#include <exception>
using boost::property_tree::ptree;
using namespace std;
const string FILENAME = "sessionstore.js";
const string WINDOW_TAG = "windows";
struct session_settings
{
void load (const string &FILENAME);
};
void session_settings::load (const string &FILENAME)
{
ptree pt;
read_json (FILENAME, pt);
}
int main()
{
try
{
session_settings Settings;
Settings.load(FILENAME);
}
catch (exception &e)
{
cout << "Error: " << e.what() << endl;
}
return 0;
}
The contents of the JSON file I'm trying to read are
{"windows":[{"tabs":[{"entries":[{"url":"about:home","title":"Mozilla Firefox Start Page","ID":5,"docshellID":11,"owner_b64":"NhAra3tiRRqhyKDUVsktxQAAAAAAAAAAwAAAAAAAAEYAAQAAAAAAAS8nfAAOr03buTZBMmukiq4HoizADOUR05MxABBLoP1AAAAAAAVhYm91dAAAAARob21l4NodcC97EdOM0ABgsPwUoweiLMAM5RHTkzEAEEug/UAAAAAADm1vei1zYWZlLWFib3V0AAAABGhvbWUAAAA=","docIdentifier":5},{"url":"http://www.google.co.uk/","title":"Google","ID":6,"docshellID":11,"docIdentifier":6,"children":[{"url":"about:blank","ID":7,"docshellID":12,"owner_b64":"NhAra3tiRRqhyKDUVsktxQAAAAAAAAAAwAAAAAAAAEYAAQAAAAAAAd6UctCANBHTk5kAEEug/UAHoizADOUR05MxABBLoP1AAAAAAv////8AAABQAQAAABhodHRwOi8vd3d3Lmdvb2dsZS5jby51ay8AAAAAAAAABAAAAAcAAAAQAAAAB/////8AAAAH/////wAAAAcAAAAQAAAAFwAAAAEAAAAXAAAAAQAAABcAAAABAAAAGAAAAAAAAAAY/////wAAABf/////AAAAF/////8AAAAX/////wEAAAAAAAAAAAABAAA=","docIdentifier":7,"scroll":"0,0"}],"formdata":{"#csi":"1","#hcache":"{\"BInSTfL-EtSt8QOl24nrCg\":[[69,{}],[14,{}],[60,{}],[81,{\"persisted\":true}],[42,{}],[43,{}],[83,{}],[95,{\"kfe\":{\"kfeHost\":\"clients1.google.co.uk\",\"kfeUrlPrefix\":\"/webpagethumbnail?r=2&f=2&s=300:585&query=&hl=en&gl=uk\",\"maxPrefetchConnections\":2,\"prefetch\":90,\"slowConnection\":false},\"logging\":{\"csiFraction\":0.05,\"gen204Fraction\":0.05},\"msgs\":{\"loading\":\"Still loading...\",\"mute\":\"Mute\",\"noPreview\":\"Preview not available\",\"sound\":\"Sound:\",\"soundOff\":\"off\",\"soundOn\":\"on\",\"unmute\":\"Unmute\"},\"pb\":{\"desiredHeight\":585,\"desiredWidth\":300,\"minHeight\":200,\"minWidth\":300},\"time\":{\"hoverClose\":300,\"hoverModeTimeout\":60,\"hoverOpen\":125,\"loading\":100,\"longHoverOpen\":725,\"prefetchOnLoad\":3000,\"timeout\":2500}}],[78,{}],[25,{\"m\":{\"bks\":true,\"blg\":true,\"dsc\":true,\"evn\":true,\"frm\":true,\"isch\":true,\"klg\":true,\"mbl\":true,\"nws\":true,\"plcs\":true,\"ppl\":true,\"prc\":true,\"pts\":true,\"rcp\":true,\"shop\":true,\"vid\":true},\"t\":null}],[64,{}],[105,{}],[22,{\"m_errors\":{\"32\":\"Sorry, no more results to show.\",\"default\":\"<font color=red>Error:</font> The server could not complete your request. Try again in 30 seconds.\"},\"m_tip\":\"Click for more information\"}],[77,{}],[84,{}],[99,{}],[29,{\"mcr\":5}],[92,{\"avgTtfc\":2000,\"fd\":1000,\"fl\":true,\"focus\":true,\"hpt\":250,\"kn\":true,\"mds\":\"clir,clue,dfn,evn,frim,klg,prc,rl,show,sp,sts,ww,mbl_he,mbl_hs,mbl_re,mbl_rs,mbl_sv,isch\",\"msg\":{\"dym\":\"Did you mean:\",\"gs\":\"Google Search\",\"kntt\":\"Use the up and down arrow keys to select each result. Press Enter to go to the selection.\",\"sif\":\"Search instead for\",\"srf\":\"Showing results for\"},\"odef\":true,\"ophe\":true,\"pq\":true,\"rpt\":41,\"tct\":\" ?\",\"tdur\":50}],[24,{}],[38,{}]]}"},"scroll":"0,0"}],"index":2,"hidden":false,"attributes":{"image":"http://www.google.co.uk/favicon.ico"},"storage":{"http://www.google.co.uk":{"web-v":"12_c9c918f0"}}}],"selected":1,"_closedTabs":[],"width":994,"height":688,"screenX":1650,"screenY":24,"sizemode":"normal","title":"Google"}],"selectedWindow":0,"_closedWindows":[{"tabs":[{"entries":[{"url":"about:home","title":"Mozilla Firefox Start Page","ID":0,"docshellID":5,"owner_b64":"NhAra3tiRRqhyKDUVsktxQAAAAAAAAAAwAAAAAAAAEYAAQAAAAAAAS8nfAAOr03buTZBMmukiq4HoizADOUR05MxABBLoP1AAAAAAAVhYm91dAAAAARob21l4NodcC97EdOM0ABgsPwUoweiLMAM5RHTkzEAEEug/UAAAAAADm1vei1zYWZlLWFib3V0AAAABGhvbWUAAAA="},{"url":"http://www.facebook.com/","title":"Welcome to Facebook - Log In, Sign Up or Learn More","ID":1,"docshellID":5,"docIdentifier":1,"formdata":{"//xhtml:div[#id='reg_form_box']/xhtml:table/xhtml:tbody/xhtml:tr[6]/xhtml:td[2]/xhtml:div/xhtml:div/xhtml:select":0,"//xhtml:div[#id='reg_form_box']/xhtml:table/xhtml:tbody/xhtml:tr[6]/xhtml:td[2]/xhtml:div/xhtml:div/xhtml:select[2]":0,"#sex":0,"#birthday_month":0,"#birthday_day":0,"#birthday_year":0},"scroll":"0,0"}],"index":2,"hidden":false,"attributes":{"image":"http://www.facebook.com/favicon.ico"}},{"entries":[{"url":"http://twitter.com/","title":"Twitter","ID":3,"docshellID":6,"docIdentifier":3,"children":[{"url":"http://api.twitter.com/receiver.html","ID":4,"docshellID":7,"referrer":"http://twitter.com/","docIdentifier":4,"scroll":"0,0"}],"formdata":{},"scroll":"0,0"}],"index":1,"hidden":false,"attributes":{"image":"http://twitter.com/phoenix/favicon.ico"}}],"selected":2,"_closedTabs":[],"width":994,"height":688,"screenX":1366,"screenY":307,"sizemode":"normal","cookies":[{"host":".facebook.com","value":"J4-69","path":"/","name":"lsd"},{"host":".facebook.com","value":"http%3A%2F%2Fwww.facebook.com%2F","path":"/","name":"reg_fb_gate"},{"host":".facebook.com","value":"http%3A%2F%2Fwww.facebook.com%2F","path":"/","name":"reg_fb_ref"},{"host":".facebook.com","value":"994x624","path":"/","name":"wd"},{"host":".twitter.com","value":"43838368","path":"/","name":"__utmc"},{"host":"twitter.com","value":"4bfz%2B%2BmebEkRkMWFCXm%2FCUOsvDoVeFTl","path":"/","name":"original_referer"},{"host":"scribe.twitter.com","value":"4bfz%2B%2BmebEkRkMWFCXm%2FCUOsvDoVeFTl","path":"/","name":"original_referer"},{"host":".twitter.com","value":"BAh7CToPY3JlYXRlZF9hdGwrCDoVZ%252F4vAToMY3NyZl9pZCIlODE2MGI1ZjJh%250AYmViNDMwODMxNDlkN2U5ZDg5Yjk4ZmU6B2lkIiU2N2I4YjdmNGExNWFkNzlk%250AODI0MDVjMGM1NmMzYjVhYSIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6%250ARmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA%253D%253D--8b0d751e9774c5cfaa61fdec567cb782aa8757dd","path":"/","name":"_twitter_sess","httponly":true},{"host":".twitter.com","value":"43838368","path":"/","name":"__utmc"},{"host":"twitter.com","value":"4bfz%2B%2BmebEkRkMWFCXm%2FCUOsvDoVeFTl","path":"/","name":"original_referer"},{"host":"scribe.twitter.com","value":"4bfz%2B%2BmebEkRkMWFCXm%2FCUOsvDoVeFTl","path":"/","name":"original_referer"},{"host":".twitter.com","value":"BAh7CToPY3JlYXRlZF9hdGwrCDoVZ%252F4vAToMY3NyZl9pZCIlODE2MGI1ZjJh%250AYmViNDMwODMxNDlkN2U5ZDg5Yjk4ZmU6B2lkIiU2N2I4YjdmNGExNWFkNzlk%250AODI0MDVjMGM1NmMzYjVhYSIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6%250ARmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA%253D%253D--8b0d751e9774c5cfaa61fdec567cb782aa8757dd","path":"/","name":"_twitter_sess","httponly":true}],"title":"Twitter"}],"session":{"state":"stopped","lastUpdate":1305658398727}}
and when I tried to load that with my program I got the error
Error: sessionstore.js(1): expected value
Since the file is formatted all on a single line, this meant the error could be anywhere in the file, so I ran it though a Javascript beautifier, keeping the default options, and pasted the results back into the original file and executed the program.
The formatted JSON is
{
"windows": [{
"tabs": [{
"entries": [{
"url": "about:home",
"title": "Mozilla Firefox Start Page",
"ID": 5,
"docshellID": 11,
"owner_b64": "NhAra3tiRRqhyKDUVsktxQAAAAAAAAAAwAAAAAAAAEYAAQAAAAAAAS8nfAAOr03buTZBMmukiq4HoizADOUR05MxABBLoP1AAAAAAAVhYm91dAAAAARob21l4NodcC97EdOM0ABgsPwUoweiLMAM5RHTkzEAEEug/UAAAAAADm1vei1zYWZlLWFib3V0AAAABGhvbWUAAAA=",
"docIdentifier": 5
}, {
"url": "http://www.google.co.uk/",
"title": "Google",
"ID": 6,
"docshellID": 11,
"docIdentifier": 6,
"children": [{
"url": "about:blank",
"ID": 7,
"docshellID": 12,
"owner_b64": "NhAra3tiRRqhyKDUVsktxQAAAAAAAAAAwAAAAAAAAEYAAQAAAAAAAd6UctCANBHTk5kAEEug/UAHoizADOUR05MxABBLoP1AAAAAAv////8AAABQAQAAABhodHRwOi8vd3d3Lmdvb2dsZS5jby51ay8AAAAAAAAABAAAAAcAAAAQAAAAB/////8AAAAH/////wAAAAcAAAAQAAAAFwAAAAEAAAAXAAAAAQAAABcAAAABAAAAGAAAAAAAAAAY/////wAAABf/////AAAAF/////8AAAAX/////wEAAAAAAAAAAAABAAA=",
"docIdentifier": 7,
"scroll": "0,0"
}],
"formdata": {
"#csi": "1",
"#hcache": "{\"BInSTfL-EtSt8QOl24nrCg\":[[69,{}],[14,{}],[60,{}],[81,{\"persisted\":true}],[42,{}],[43,{}],[83,{}],[95,{\"kfe\":{\"kfeHost\":\"clients1.google.co.uk\",\"kfeUrlPrefix\":\"/webpagethumbnail?r=2&f=2&s=300:585&query=&hl=en&gl=uk\",\"maxPrefetchConnections\":2,\"prefetch\":90,\"slowConnection\":false},\"logging\":{\"csiFraction\":0.05,\"gen204Fraction\":0.05},\"msgs\":{\"loading\":\"Still loading...\",\"mute\":\"Mute\",\"noPreview\":\"Preview not available\",\"sound\":\"Sound:\",\"soundOff\":\"off\",\"soundOn\":\"on\",\"unmute\":\"Unmute\"},\"pb\":{\"desiredHeight\":585,\"desiredWidth\":300,\"minHeight\":200,\"minWidth\":300},\"time\":{\"hoverClose\":300,\"hoverModeTimeout\":60,\"hoverOpen\":125,\"loading\":100,\"longHoverOpen\":725,\"prefetchOnLoad\":3000,\"timeout\":2500}}],[78,{}],[25,{\"m\":{\"bks\":true,\"blg\":true,\"dsc\":true,\"evn\":true,\"frm\":true,\"isch\":true,\"klg\":true,\"mbl\":true,\"nws\":true,\"plcs\":true,\"ppl\":true,\"prc\":true,\"pts\":true,\"rcp\":true,\"shop\":true,\"vid\":true},\"t\":null}],[64,{}],[105,{}],[22,{\"m_errors\":{\"32\":\"Sorry, no more results to show.\",\"default\":\"<font color=red>Error:</font> The server could not complete your request. Try again in 30 seconds.\"},\"m_tip\":\"Click for more information\"}],[77,{}],[84,{}],[99,{}],[29,{\"mcr\":5}],[92,{\"avgTtfc\":2000,\"fd\":1000,\"fl\":true,\"focus\":true,\"hpt\":250,\"kn\":true,\"mds\":\"clir,clue,dfn,evn,frim,klg,prc,rl,show,sp,sts,ww,mbl_he,mbl_hs,mbl_re,mbl_rs,mbl_sv,isch\",\"msg\":{\"dym\":\"Did you mean:\",\"gs\":\"Google Search\",\"kntt\":\"Use the up and down arrow keys to select each result. Press Enter to go to the selection.\",\"sif\":\"Search instead for\",\"srf\":\"Showing results for\"},\"odef\":true,\"ophe\":true,\"pq\":true,\"rpt\":41,\"tct\":\" ?\",\"tdur\":50}],[24,{}],[38,{}]]}"
},
"scroll": "0,0"
}],
"index": 2,
"hidden": false,
"attributes": {
"image": "http://www.google.co.uk/favicon.ico"
},
"storage": {
"http://www.google.co.uk": {
"web-v": "12_c9c918f0"
}
}
}],
"selected": 1,
"_closedTabs": [],
"width": 994,
"height": 688,
"screenX": 1650,
"screenY": 24,
"sizemode": "normal",
"title": "Google"
}],
"selectedWindow": 0,
"_closedWindows": [{
"tabs": [{
"entries": [{
"url": "about:home",
"title": "Mozilla Firefox Start Page",
"ID": 0,
"docshellID": 5,
"owner_b64": "NhAra3tiRRqhyKDUVsktxQAAAAAAAAAAwAAAAAAAAEYAAQAAAAAAAS8nfAAOr03buTZBMmukiq4HoizADOUR05MxABBLoP1AAAAAAAVhYm91dAAAAARob21l4NodcC97EdOM0ABgsPwUoweiLMAM5RHTkzEAEEug/UAAAAAADm1vei1zYWZlLWFib3V0AAAABGhvbWUAAAA="
}, {
"url": "http://www.facebook.com/",
"title": "Welcome to Facebook - Log In, Sign Up or Learn More",
"ID": 1,
"docshellID": 5,
"docIdentifier": 1,
"formdata": {
"//xhtml:div[#id='reg_form_box']/xhtml:table/xhtml:tbody/xhtml:tr[6]/xhtml:td[2]/xhtml:div/xhtml:div/xhtml:select": 0,
"//xhtml:div[#id='reg_form_box']/xhtml:table/xhtml:tbody/xhtml:tr[6]/xhtml:td[2]/xhtml:div/xhtml:div/xhtml:select[2]": 0,
"#sex": 0,
"#birthday_month": 0,
"#birthday_day": 0,
"#birthday_year": 0
},
"scroll": "0,0"
}],
"index": 2,
"hidden": false,
"attributes": {
"image": "http://www.facebook.com/favicon.ico"
}
}, {
"entries": [{
"url": "http://twitter.com/",
"title": "Twitter",
"ID": 3,
"docshellID": 6,
"docIdentifier": 3,
"children": [{
"url": "http://api.twitter.com/receiver.html",
"ID": 4,
"docshellID": 7,
"referrer": "http://twitter.com/",
"docIdentifier": 4,
"scroll": "0,0"
}],
"formdata": {},
"scroll": "0,0"
}],
"index": 1,
"hidden": false,
"attributes": {
"image": "http://twitter.com/phoenix/favicon.ico"
}
}],
"selected": 2,
"_closedTabs": [],
"width": 994,
"height": 688,
"screenX": 1366,
"screenY": 307,
"sizemode": "normal",
"cookies": [{
"host": ".facebook.com",
"value": "J4-69",
"path": "/",
"name": "lsd"
}, {
"host": ".facebook.com",
"value": "http%3A%2F%2Fwww.facebook.com%2F",
"path": "/",
"name": "reg_fb_gate"
}, {
"host": ".facebook.com",
"value": "http%3A%2F%2Fwww.facebook.com%2F",
"path": "/",
"name": "reg_fb_ref"
}, {
"host": ".facebook.com",
"value": "994x624",
"path": "/",
"name": "wd"
}, {
"host": ".twitter.com",
"value": "43838368",
"path": "/",
"name": "__utmc"
}, {
"host": "twitter.com",
"value": "4bfz%2B%2BmebEkRkMWFCXm%2FCUOsvDoVeFTl",
"path": "/",
"name": "original_referer"
}, {
"host": "scribe.twitter.com",
"value": "4bfz%2B%2BmebEkRkMWFCXm%2FCUOsvDoVeFTl",
"path": "/",
"name": "original_referer"
}, {
"host": ".twitter.com",
"value": "BAh7CToPY3JlYXRlZF9hdGwrCDoVZ%252F4vAToMY3NyZl9pZCIlODE2MGI1ZjJh%250AYmViNDMwODMxNDlkN2U5ZDg5Yjk4ZmU6B2lkIiU2N2I4YjdmNGExNWFkNzlk%250AODI0MDVjMGM1NmMzYjVhYSIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6%250ARmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA%253D%253D--8b0d751e9774c5cfaa61fdec567cb782aa8757dd",
"path": "/",
"name": "_twitter_sess",
"httponly": true
}, {
"host": ".twitter.com",
"value": "43838368",
"path": "/",
"name": "__utmc"
}, {
"host": "twitter.com",
"value": "4bfz%2B%2BmebEkRkMWFCXm%2FCUOsvDoVeFTl",
"path": "/",
"name": "original_referer"
}, {
"host": "scribe.twitter.com",
"value": "4bfz%2B%2BmebEkRkMWFCXm%2FCUOsvDoVeFTl",
"path": "/",
"name": "original_referer"
}, {
"host": ".twitter.com",
"value": "BAh7CToPY3JlYXRlZF9hdGwrCDoVZ%252F4vAToMY3NyZl9pZCIlODE2MGI1ZjJh%250AYmViNDMwODMxNDlkN2U5ZDg5Yjk4ZmU6B2lkIiU2N2I4YjdmNGExNWFkNzlk%250AODI0MDVjMGM1NmMzYjVhYSIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6%250ARmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA%253D%253D--8b0d751e9774c5cfaa61fdec567cb782aa8757dd",
"path": "/",
"name": "_twitter_sess",
"httponly": true
}],
"title": "Twitter"
}],
"session": {
"state": "stopped",
"lastUpdate": 1305658398727
}
}
The error
Error: sessionstore.js(179): expected value
now identifies the fault as being on the third-last line, the one that reads "lastUpdate": 1305658398727. From what I've read about the JSON format, this sounds to me like a comma or bracket is missing from this line, but this is a file that has been produced my Mozilla to work with Firefox, and I don't believe that they would make a mistake like that, so I am lead to believe that there is a problem with the JSON parser in Boost. Can anyone please confirm if this is the case, or if I'm the one doing something wrong?
I think the problem is this value is bigger than an int or a double. I don't know what data type uses BOOST JSON for reading numbers. To test this, just change the number to be a string and parse it again. In the standard, numbers are not limited, but you have to select a data type to represent them, and maybe they selected double, clearly not enough for this number. I'll take a look to see if you can configure the type used for numbers.
EDIT:
Looking again at the implementation, the "number" rule is implemented using Spirit as follows:
number
= strict_real_p
| int_p
;
Looking at Spirit strict_real_p uses double as the underlying type, and int_p actually uses an int.
The bad news is that, for what I see in the code, this is not configurable, so you have to change the JSON to be interpreted.
After receiving answers from Diego Sevilla and c-smile, I did a bit of Googling to figure out how I would incorporate their suggestions into Boost, since changing the JSON file unfortunately isn't an option in my case, and I came across this ticket on the Boost bug tracker that describes my exact problem. It has since been fixed and released with Boost 1.45. I, however, am using version 1.42 from the Ubuntu repositories, so will need to install the newer version manually.
As Diego said that is because 1305658398727 does not fit into neither strict_real_p nor int_p production.
I suspect you will need either other JSON parser or to modify Spirit definitions by yourself.
Either like this:
number
= strict_real_p
| int_p
| int64_p
;
or just as:
number
= real_p;
Ideally date/time in JSON should be presented by strings in ISO format. In this case you will not have such problems. I suspect that data there is just a number of milliseconds since 1970-01-01 (JavaScript Date.valueOf())