Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
2c5bfec0
Commit
2c5bfec0
authored
Jan 31, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #55 from oroce/elasticsearch-basicauth
basic authentication added for elasticsearch
parents
89224401
a56a2b00
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
10 deletions
+33
-10
src/app/components/settings.js
+5
-2
src/app/controllers/dash.js
+1
-1
src/app/controllers/metricKeys.js
+9
-3
src/app/services/dashboard.js
+11
-3
src/vendor/elasticjs/elastic-angular-client.js
+7
-1
No files found.
src/app/components/settings.js
View file @
2c5bfec0
...
@@ -28,16 +28,19 @@ function (_, crypto) {
...
@@ -28,16 +28,19 @@ function (_, crypto) {
settings
[
key
]
=
typeof
options
[
key
]
!==
'undefined'
?
options
[
key
]
:
defaults
[
key
];
settings
[
key
]
=
typeof
options
[
key
]
!==
'undefined'
?
options
[
key
]
:
defaults
[
key
];
});
});
var
url
=
settings
.
graphiteUrl
;
var
basicAuth
=
function
(
url
)
{
var
passwordAt
=
url
.
indexOf
(
'@'
);
var
passwordAt
=
url
.
indexOf
(
'@'
);
if
(
passwordAt
>
0
)
{
if
(
passwordAt
>
0
)
{
var
userStart
=
url
.
indexOf
(
'//'
)
+
2
;
var
userStart
=
url
.
indexOf
(
'//'
)
+
2
;
var
userAndPassword
=
url
.
substring
(
userStart
,
passwordAt
);
var
userAndPassword
=
url
.
substring
(
userStart
,
passwordAt
);
var
bytes
=
crypto
.
charenc
.
Binary
.
stringToBytes
(
userAndPassword
);
var
bytes
=
crypto
.
charenc
.
Binary
.
stringToBytes
(
userAndPassword
);
var
base64
=
crypto
.
util
.
bytesToBase64
(
bytes
);
var
base64
=
crypto
.
util
.
bytesToBase64
(
bytes
);
settings
.
graphiteBasicAuth
=
base64
;
return
base64
;
}
}
};
settings
.
graphiteBasicAuth
=
basicAuth
(
settings
.
graphiteUrl
);
settings
.
elasticsearchBasicAuth
=
basicAuth
(
settings
.
elasticsearch
);
return
settings
;
return
settings
;
};
};
});
});
src/app/controllers/dash.js
View file @
2c5bfec0
...
@@ -58,7 +58,7 @@ function (angular, $, config, _) {
...
@@ -58,7 +58,7 @@ function (angular, $, config, _) {
$scope
.
reset_row
();
$scope
.
reset_row
();
$scope
.
ejs
=
ejsResource
(
config
.
elasticsearch
);
$scope
.
ejs
=
ejsResource
(
config
.
elasticsearch
,
config
.
elasticsearchBasicAuth
);
$scope
.
bindKeyboardShortcuts
();
$scope
.
bindKeyboardShortcuts
();
};
};
...
...
src/app/controllers/metricKeys.js
View file @
2c5bfec0
...
@@ -10,7 +10,13 @@ function (angular, _, config) {
...
@@ -10,7 +10,13 @@ function (angular, _, config) {
module
.
controller
(
'MetricKeysCtrl'
,
function
(
$scope
,
$http
,
$q
)
{
module
.
controller
(
'MetricKeysCtrl'
,
function
(
$scope
,
$http
,
$q
)
{
var
elasticSearchUrlForMetricIndex
=
config
.
elasticsearch
+
'/'
+
config
.
grafana_metrics_index
+
'/'
;
var
elasticSearchUrlForMetricIndex
=
config
.
elasticsearch
+
'/'
+
config
.
grafana_metrics_index
+
'/'
;
var
httpOptions
=
{};
if
(
config
.
elasticsearchBasicAuth
)
{
options
.
withCredentials
=
true
;
options
.
headers
=
{
"Authorization"
:
"Basic "
+
config
.
elasticsearchBasicAuth
};
}
$scope
.
init
=
function
()
{
$scope
.
init
=
function
()
{
$scope
.
metricPath
=
"prod.apps.api.boobarella.*"
;
$scope
.
metricPath
=
"prod.apps.api.boobarella.*"
;
$scope
.
metricCounter
=
0
;
$scope
.
metricCounter
=
0
;
...
@@ -77,7 +83,7 @@ function (angular, _, config) {
...
@@ -77,7 +83,7 @@ function (angular, _, config) {
function
deleteIndex
()
function
deleteIndex
()
{
{
var
deferred
=
$q
.
defer
();
var
deferred
=
$q
.
defer
();
$http
.
delete
(
elasticSearchUrlForMetricIndex
)
$http
.
delete
(
elasticSearchUrlForMetricIndex
,
httpOptions
)
.
success
(
function
()
{
.
success
(
function
()
{
deferred
.
resolve
(
'ok'
);
deferred
.
resolve
(
'ok'
);
})
})
...
@@ -124,7 +130,7 @@ function (angular, _, config) {
...
@@ -124,7 +130,7 @@ function (angular, _, config) {
}
}
}
}
}
}
});
}
,
httpOptions
);
}
}
function
receiveMetric
(
result
)
{
function
receiveMetric
(
result
)
{
...
...
src/app/services/dashboard.js
View file @
2c5bfec0
...
@@ -47,7 +47,7 @@ function (angular, $, kbn, _, config, moment, Modernizr) {
...
@@ -47,7 +47,7 @@ function (angular, $, kbn, _, config, moment, Modernizr) {
};
};
// An elasticJS client to use
// An elasticJS client to use
var
ejs
=
ejsResource
(
config
.
elasticsearch
);
var
ejs
=
ejsResource
(
config
.
elasticsearch
,
config
.
elasticsearchBasicAuth
);
var
gist_pattern
=
/
(
^
\d{5,}
$
)
|
(
^
[
a-z0-9
]{10,}
$
)
|
(
gist.github.com
(\/
*.*
)\/[
a-z0-9
]{5,}\/
*$
)
/
;
var
gist_pattern
=
/
(
^
\d{5,}
$
)
|
(
^
[
a-z0-9
]{10,}
$
)
|
(
gist.github.com
(\/
*.*
)\/[
a-z0-9
]{5,}\/
*$
)
/
;
// Store a reference to this
// Store a reference to this
...
@@ -286,13 +286,21 @@ function (angular, $, kbn, _, config, moment, Modernizr) {
...
@@ -286,13 +286,21 @@ function (angular, $, kbn, _, config, moment, Modernizr) {
};
};
this
.
elasticsearch_load
=
function
(
type
,
id
)
{
this
.
elasticsearch_load
=
function
(
type
,
id
)
{
return
$http
(
{
var
options
=
{
url
:
config
.
elasticsearch
+
"/"
+
config
.
grafana_index
+
"/"
+
type
+
"/"
+
id
+
'?'
+
new
Date
().
getTime
(),
url
:
config
.
elasticsearch
+
"/"
+
config
.
grafana_index
+
"/"
+
type
+
"/"
+
id
+
'?'
+
new
Date
().
getTime
(),
method
:
"GET"
,
method
:
"GET"
,
transformResponse
:
function
(
response
)
{
transformResponse
:
function
(
response
)
{
return
renderTemplate
(
angular
.
fromJson
(
response
).
_source
.
dashboard
,
$routeParams
);
return
renderTemplate
(
angular
.
fromJson
(
response
).
_source
.
dashboard
,
$routeParams
);
}
}
}).
error
(
function
(
data
,
status
)
{
};
if
(
config
.
elasticsearchBasicAuth
)
{
options
.
withCredentials
=
true
;
options
.
headers
=
{
"Authorization"
:
"Basic "
+
config
.
elasticsearchBasicAuth
};
}
return
$http
(
options
)
.
error
(
function
(
data
,
status
)
{
if
(
status
===
0
)
{
if
(
status
===
0
)
{
alertSrv
.
set
(
'Error'
,
"Could not contact Elasticsearch at "
+
config
.
elasticsearch
+
alertSrv
.
set
(
'Error'
,
"Could not contact Elasticsearch at "
+
config
.
elasticsearch
+
". Please ensure that Elasticsearch is reachable from your system."
,
'error'
);
". Please ensure that Elasticsearch is reachable from your system."
,
'error'
);
...
...
src/vendor/elasticjs/elastic-angular-client.js
View file @
2c5bfec0
...
@@ -13,7 +13,7 @@ be injected into your angular controllers.
...
@@ -13,7 +13,7 @@ be injected into your angular controllers.
angular
.
module
(
'elasticjs.service'
,
[])
angular
.
module
(
'elasticjs.service'
,
[])
.
factory
(
'ejsResource'
,
[
'$http'
,
function
(
$http
)
{
.
factory
(
'ejsResource'
,
[
'$http'
,
function
(
$http
)
{
return
function
(
config
)
{
return
function
(
config
,
basicAuth
)
{
var
var
...
@@ -43,6 +43,12 @@ angular.module('elasticjs.service', [])
...
@@ -43,6 +43,12 @@ angular.module('elasticjs.service', [])
config
.
server
=
''
;
config
.
server
=
''
;
}
}
// set authentication header
if
(
basicAuth
||
config
.
basicAuth
)
{
config
.
headers
=
angular
.
extend
(
config
.
headers
||
{},
{
"Authorization"
:
"Basic "
+
(
basicAuth
||
config
.
basicAuth
)
});
}
/* implement the elastic.js client interface for angular */
/* implement the elastic.js client interface for angular */
ejs
.
client
=
{
ejs
.
client
=
{
server
:
function
(
s
)
{
server
:
function
(
s
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment